comparison DEPENDENCIES/generic/include/boost/multiprecision/traits/explicit_conversion.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
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{ namespace multiprecision{ namespace detail{
15
16 template <int N>
17 struct dummy_size{};
18
19 template<typename S, typename T>
20 struct has_generic_interconversion
21 {
22 typedef typename mpl::if_c<
23 is_number<S>::value && is_number<T>::value,
24 typename mpl::if_c<
25 number_category<S>::value == number_kind_integer,
26 typename mpl::if_c<
27 number_category<T>::value == number_kind_integer
28 || number_category<T>::value == number_kind_floating_point
29 || number_category<T>::value == number_kind_rational
30 || number_category<T>::value == number_kind_fixed_point,
31 mpl::true_,
32 mpl::false_
33 >::type,
34 typename mpl::if_c<
35 number_category<S>::value == number_kind_rational,
36 typename mpl::if_c<
37 number_category<T>::value == number_kind_rational
38 || number_category<T>::value == number_kind_rational,
39 mpl::true_,
40 mpl::false_
41 >::type,
42 typename mpl::if_c<
43 number_category<T>::value == number_kind_floating_point,
44 mpl::true_,
45 mpl::false_
46 >::type
47 >::type
48 >::type,
49 mpl::false_
50 >::type type;
51 };
52
53 template<typename S, typename T>
54 struct is_explicitly_convertible_imp
55 {
56 #ifndef BOOST_NO_SFINAE_EXPR
57 template<typename S1, typename T1>
58 static type_traits::yes_type selector(dummy_size<sizeof(static_cast<T1>(declval<S1>()))>*);
59
60 template<typename S1, typename T1>
61 static type_traits::no_type selector(...);
62
63 static const bool value = sizeof(selector<S,T>(0)) == sizeof(type_traits::yes_type);
64
65 typedef boost::integral_constant<bool,value> type;
66 #else
67 typedef typename has_generic_interconversion<S, T>::type gen_type;
68 typedef mpl::bool_<boost::is_convertible<S, T>::value || gen_type::value> type;
69 #endif
70 };
71
72 template<typename From, typename To>
73 struct is_explicitly_convertible : public is_explicitly_convertible_imp<From, To>::type
74 {
75 };
76
77 }}} // namespaces
78
79 #endif
80