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)
7 #ifndef BOOST_MP_RESTRICTED_CONVERSION_HPP
8 #define BOOST_MP_RESTRICTED_CONVERSION_HPP
10 #include <boost/multiprecision/traits/explicit_conversion.hpp>
11 #include <boost/mpl/if.hpp>
12 #include <boost/multiprecision/detail/number_base.hpp>
14 namespace boost { namespace multiprecision { namespace detail {
16 template <class From, class To>
17 struct is_lossy_conversion
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),
24 mpl::false_>::type type;
25 static const bool value = type::value;
28 template <typename From, typename To>
29 struct is_restricted_conversion
31 typedef typename mpl::if_c<
32 ((is_explicitly_convertible<From, To>::value && !is_convertible<From, To>::value) || is_lossy_conversion<From, To>::value),
34 mpl::false_>::type type;
35 static const bool value = type::value;
38 }}} // namespace boost::multiprecision::detail
40 #endif // BOOST_MP_RESTRICTED_CONVERSION_HPP