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_IS_RESTRICTED_CONVERSION_HPP
8#define BOOST_MP_IS_RESTRICTED_CONVERSION_HPP
9
10#include <boost/multiprecision/traits/explicit_conversion.hpp>
11#include <boost/multiprecision/detail/number_base.hpp>
12
13namespace boost { namespace multiprecision { namespace detail {
14
15template <class From, class To>
16struct is_lossy_conversion
17{
18 static constexpr bool category_conditional_is_true =
19 ( (static_cast<boost::multiprecision::number_category_type>(number_category<From>::value) == number_kind_floating_point)
20 && (static_cast<boost::multiprecision::number_category_type>(number_category<To >::value) == number_kind_integer))
21 || ( (static_cast<boost::multiprecision::number_category_type>(number_category<From>::value) == number_kind_rational)
22 && (static_cast<boost::multiprecision::number_category_type>(number_category<To >::value) == number_kind_integer))
23 || ( (static_cast<boost::multiprecision::number_category_type>(number_category<From>::value) == number_kind_fixed_point)
24 && (static_cast<boost::multiprecision::number_category_type>(number_category<To >::value) == number_kind_integer))
25 || (static_cast<boost::multiprecision::number_category_type>(number_category<From>::value) == number_kind_unknown)
26 || (static_cast<boost::multiprecision::number_category_type>(number_category<To >::value) == number_kind_unknown);
27
28 using type = typename std::conditional<category_conditional_is_true,
29 std::integral_constant<bool, true>,
30 std::integral_constant<bool, false>>::type;
31
32 static constexpr bool value = type::value;
33};
34
35template <typename From, typename To>
36struct is_restricted_conversion
37{
38 using type = typename std::conditional<
39 ((is_explicitly_convertible<From, To>::value && !std::is_convertible<From, To>::value) || is_lossy_conversion<From, To>::value),
40 std::integral_constant<bool, true>,
41 std::integral_constant<bool, false>>::type;
42 static constexpr const bool value = type::value;
43};
44
45}}} // namespace boost::multiprecision::detail
46
47#endif // BOOST_MP_IS_RESTRICTED_CONVERSION_HPP
48

source code of boost/libs/multiprecision/include/boost/multiprecision/traits/is_restricted_conversion.hpp