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 7 #ifndef BOOST_MP_RESTRICTED_CONVERSION_HPP 8 #define BOOST_MP_RESTRICTED_CONVERSION_HPP 9 10 #include <boost/multiprecision/traits/explicit_conversion.hpp> 11 #include <boost/mpl/if.hpp> 12 #include <boost/multiprecision/detail/number_base.hpp> 13 14 namespace boost { namespace multiprecision { namespace detail { 15 16 template <class From, class To> 17 struct is_lossy_conversion 18 { 19 typedef typename mpl::if_c< 20 ((number_category<From>::value == number_kind_floating_point) && (number_category<To>::value == number_kind_integer)) 21 /* || ((number_category<From>::value == number_kind_floating_point) && (number_category<To>::value == number_kind_rational))*/ 22 || ((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), 23 mpl::true_, 24 mpl::false_>::type type; 25 static const bool value = type::value; 26 }; 27 28 template <typename From, typename To> 29 struct is_restricted_conversion 30 { 31 typedef typename mpl::if_c< 32 ((is_explicitly_convertible<From, To>::value && !is_convertible<From, To>::value) || is_lossy_conversion<From, To>::value), 33 mpl::true_, 34 mpl::false_>::type type; 35 static const bool value = type::value; 36 }; 37 38 }}} // namespace boost::multiprecision::detail 39 40 #endif // BOOST_MP_RESTRICTED_CONVERSION_HPP 41