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
14namespace boost {
15namespace multiprecision {
16namespace detail {
17
18template <unsigned int N>
19struct dummy_size
20{};
21
22template <typename S, typename T>
23struct 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
46template <typename S, typename T>
47struct 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
60template <typename From, typename To>
61struct is_explicitly_convertible : public is_explicitly_convertible_imp<From, To>::type
62{
63};
64
65}}} // namespace boost::multiprecision::detail
66
67#endif
68

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