| 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_EXPLICIT_CONVERSION_HPP |
| 8 | #define BOOST_MP_EXPLICIT_CONVERSION_HPP |
| 9 | |
| 10 | #include <type_traits> |
| 11 | #include <boost/multiprecision/detail/standalone_config.hpp> |
| 12 | #include <boost/multiprecision/detail/number_base.hpp> // number_category |
| 13 | |
| 14 | namespace boost { |
| 15 | namespace multiprecision { |
| 16 | namespace detail { |
| 17 | |
| 18 | template <unsigned int N> |
| 19 | struct dummy_size |
| 20 | {}; |
| 21 | |
| 22 | template <typename S, typename T> |
| 23 | struct has_generic_interconversion |
| 24 | { |
| 25 | using type = typename std::conditional< |
| 26 | is_number<S>::value && is_number<T>::value, |
| 27 | typename std::conditional< |
| 28 | number_category<S>::value == number_kind_integer, |
| 29 | typename std::conditional< |
| 30 | number_category<T>::value == number_kind_integer || number_category<T>::value == number_kind_floating_point || number_category<T>::value == number_kind_rational || number_category<T>::value == number_kind_fixed_point, |
| 31 | std::true_type, |
| 32 | std::false_type >::type, |
| 33 | typename std::conditional< |
| 34 | number_category<S>::value == number_kind_rational, |
| 35 | typename std::conditional< |
| 36 | number_category<T>::value == number_kind_rational || number_category<T>::value == number_kind_rational, |
| 37 | std::true_type, |
| 38 | std::false_type >::type, |
| 39 | typename std::conditional< |
| 40 | number_category<T>::value == number_kind_floating_point, |
| 41 | std::true_type, |
| 42 | std::false_type >::type>::type>::type, |
| 43 | std::false_type >::type; |
| 44 | }; |
| 45 | |
| 46 | template <typename S, typename T> |
| 47 | struct is_explicitly_convertible_imp |
| 48 | { |
| 49 | template <typename S1, typename T1> |
| 50 | static int selector(dummy_size<static_cast<unsigned int>(sizeof(new T1(std::declval<S1>())))>*); |
| 51 | |
| 52 | template <typename S1, typename T1> |
| 53 | static char selector(...); |
| 54 | |
| 55 | static constexpr bool value = sizeof(selector<S, T>(nullptr)) == sizeof(int); |
| 56 | |
| 57 | using type = std::integral_constant<bool, value>; |
| 58 | }; |
| 59 | |
| 60 | template <typename From, typename To> |
| 61 | struct is_explicitly_convertible : public is_explicitly_convertible_imp<From, To>::type |
| 62 | { |
| 63 | }; |
| 64 | |
| 65 | }}} // namespace boost::multiprecision::detail |
| 66 | |
| 67 | #endif |
| 68 | |