is_restricted_conversion.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright Vicente J. Botet Escriba 2009-2011
  3. // Copyright 2012 John Maddock. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_MP_RESTRICTED_CONVERSION_HPP
  7. #define BOOST_MP_RESTRICTED_CONVERSION_HPP
  8. #include <boost/multiprecision/traits/explicit_conversion.hpp>
  9. #include <boost/mpl/if.hpp>
  10. #include <boost/multiprecision/detail/number_base.hpp>
  11. namespace boost { namespace multiprecision { namespace detail {
  12. template <class From, class To>
  13. struct is_lossy_conversion
  14. {
  15. typedef typename mpl::if_c<
  16. ((number_category<From>::value == number_kind_floating_point) && (number_category<To>::value == number_kind_integer))
  17. /* || ((number_category<From>::value == number_kind_floating_point) && (number_category<To>::value == number_kind_rational))*/
  18. || ((number_category<From>::value == number_kind_rational) && (number_category<To>::value == number_kind_integer)) || ((number_category<From>::value == number_kind_fixed_point) && (number_category<To>::value == number_kind_integer)) || (number_category<From>::value == number_kind_unknown) || (number_category<To>::value == number_kind_unknown),
  19. mpl::true_,
  20. mpl::false_>::type type;
  21. static const bool value = type::value;
  22. };
  23. template <typename From, typename To>
  24. struct is_restricted_conversion
  25. {
  26. typedef typename mpl::if_c<
  27. ((is_explicitly_convertible<From, To>::value && !is_convertible<From, To>::value) || is_lossy_conversion<From, To>::value),
  28. mpl::true_,
  29. mpl::false_>::type type;
  30. static const bool value = type::value;
  31. };
  32. }}} // namespace boost::multiprecision::detail
  33. #endif // BOOST_MP_RESTRICTED_CONVERSION_HPP