Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:42:24

0001 ///////////////////////////////////////////////////////////////////////////////
0002 //  Copyright Vicente J. Botet Escriba 2009-2011
0003 //  Copyright 2012 John Maddock. Distributed under the Boost
0004 //  Software License, Version 1.0. (See accompanying file
0005 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 #ifndef BOOST_MP_IS_RESTRICTED_CONVERSION_HPP
0008 #define BOOST_MP_IS_RESTRICTED_CONVERSION_HPP
0009 
0010 #include <boost/multiprecision/traits/explicit_conversion.hpp>
0011 #include <boost/multiprecision/detail/number_base.hpp>
0012 
0013 namespace boost { namespace multiprecision { namespace detail {
0014 
0015 template <class From, class To>
0016 struct is_lossy_conversion
0017 {
0018    static constexpr bool category_conditional_is_true =
0019          (   (static_cast<boost::multiprecision::number_category_type>(number_category<From>::value) == number_kind_floating_point)
0020           && (static_cast<boost::multiprecision::number_category_type>(number_category<To  >::value) == number_kind_integer))
0021       || (   (static_cast<boost::multiprecision::number_category_type>(number_category<From>::value) == number_kind_rational)
0022           && (static_cast<boost::multiprecision::number_category_type>(number_category<To  >::value) == number_kind_integer))
0023       || (   (static_cast<boost::multiprecision::number_category_type>(number_category<From>::value) == number_kind_fixed_point)
0024           && (static_cast<boost::multiprecision::number_category_type>(number_category<To  >::value) == number_kind_integer))
0025       ||     (static_cast<boost::multiprecision::number_category_type>(number_category<From>::value) == number_kind_unknown)
0026       ||     (static_cast<boost::multiprecision::number_category_type>(number_category<To  >::value) == number_kind_unknown);
0027 
0028    using type = typename std::conditional<category_conditional_is_true,
0029                                           std::integral_constant<bool, true>,
0030                                           std::integral_constant<bool, false>>::type;
0031 
0032    static constexpr bool value = type::value;
0033 };
0034 
0035 template <typename From, typename To>
0036 struct is_restricted_conversion
0037 {
0038    using type = typename std::conditional<
0039        ((is_explicitly_convertible<From, To>::value && !std::is_convertible<From, To>::value) || is_lossy_conversion<From, To>::value),
0040        std::integral_constant<bool, true>,
0041        std::integral_constant<bool, false>>::type;
0042    static constexpr const bool                     value = type::value;
0043 };
0044 
0045 }}} // namespace boost::multiprecision::detail
0046 
0047 #endif // BOOST_MP_IS_RESTRICTED_CONVERSION_HPP