]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_CONVERTIBLE_HPP | |
8 | #define BOOST_MP_EXPLICIT_CONVERTIBLE_HPP | |
9 | ||
10 | #include <boost/type_traits/is_convertible.hpp> | |
11 | #include <boost/utility/declval.hpp> | |
12 | ||
13 | ||
14 | namespace boost { | |
15 | namespace multiprecision { | |
16 | namespace detail { | |
17 | ||
18 | template <int N> | |
19 | struct dummy_size {}; | |
20 | ||
21 | template<typename S, typename T> | |
22 | struct has_generic_interconversion | |
23 | { | |
24 | typedef typename mpl::if_c < | |
25 | is_number<S>::value && is_number<T>::value, | |
26 | typename mpl::if_c < | |
27 | number_category<S>::value == number_kind_integer, | |
28 | typename mpl::if_c< | |
29 | number_category<T>::value == number_kind_integer | |
30 | || number_category<T>::value == number_kind_floating_point | |
31 | || number_category<T>::value == number_kind_rational | |
32 | || number_category<T>::value == number_kind_fixed_point, | |
33 | mpl::true_, | |
34 | mpl::false_ | |
35 | >::type, | |
36 | typename mpl::if_c< | |
37 | number_category<S>::value == number_kind_rational, | |
38 | typename mpl::if_c< | |
39 | number_category<T>::value == number_kind_rational | |
40 | || number_category<T>::value == number_kind_rational, | |
41 | mpl::true_, | |
42 | mpl::false_ | |
43 | >::type, | |
44 | typename mpl::if_c< | |
45 | number_category<T>::value == number_kind_floating_point, | |
46 | mpl::true_, | |
47 | mpl::false_ | |
48 | >::type | |
49 | >::type | |
50 | > ::type, | |
51 | mpl::false_ | |
52 | > ::type type; | |
53 | }; | |
54 | ||
55 | template<typename S, typename T> | |
56 | struct is_explicitly_convertible_imp | |
57 | { | |
58 | #ifndef BOOST_NO_SFINAE_EXPR | |
59 | template<typename S1, typename T1> | |
60 | static type_traits::yes_type selector(dummy_size<sizeof(static_cast<T1>(declval<S1>()))>*); | |
61 | ||
62 | template<typename S1, typename T1> | |
63 | static type_traits::no_type selector(...); | |
64 | ||
65 | static const bool value = sizeof(selector<S, T>(0)) == sizeof(type_traits::yes_type); | |
66 | ||
67 | typedef boost::integral_constant<bool, value> type; | |
68 | #else | |
69 | typedef typename has_generic_interconversion<S, T>::type gen_type; | |
70 | typedef mpl::bool_<boost::is_convertible<S, T>::value || gen_type::value> type; | |
71 | #endif | |
72 | }; | |
73 | ||
74 | template<typename From, typename To> | |
75 | struct is_explicitly_convertible : public is_explicitly_convertible_imp<From, To>::type | |
76 | { | |
77 | }; | |
78 | ||
79 | #ifdef BOOST_NO_SFINAE_EXPR | |
80 | template<class Backend1, expression_template_option ExpressionTemplates1, class Backend2, expression_template_option ExpressionTemplates2> | |
81 | struct is_explicitly_convertible<number<Backend1, ExpressionTemplates1>, number<Backend2, ExpressionTemplates2> > | |
82 | : public is_explicitly_convertible<Backend1, Backend2> | |
83 | { | |
84 | }; | |
85 | #endif | |
86 | ||
87 | }}} // namespaces | |
88 | ||
89 | #endif | |
90 |