]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Copyright 2015 John Maddock. Distributed under the Boost | |
3 | // Software License, Version 1.0. (See accompanying file | |
4 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
5 | ||
6 | #ifndef BOOST_MP_IS_BACKEND_HPP | |
7 | #define BOOST_MP_IS_BACKEND_HPP | |
8 | ||
1e59de90 | 9 | #include <type_traits> |
7c673cae FG |
10 | #include <boost/multiprecision/detail/number_base.hpp> |
11 | ||
92f5a8d4 TL |
12 | namespace boost { namespace multiprecision { namespace detail { |
13 | ||
92f5a8d4 | 14 | template <class T> |
1e59de90 TL |
15 | struct has_signed_types |
16 | { | |
17 | template <class U> | |
18 | static double check(U*, typename U::signed_types* = nullptr); | |
19 | static char check(...); | |
20 | static T* get(); | |
21 | static constexpr bool value = sizeof(check(get())) == sizeof(double); | |
22 | }; | |
23 | template <class T> | |
24 | struct has_unsigned_types | |
25 | { | |
26 | template <class U> | |
27 | static double check(U*, typename U::unsigned_types* = nullptr); | |
28 | static char check(...); | |
29 | static T* get(); | |
30 | static constexpr bool value = sizeof(check(get())) == sizeof(double); | |
31 | }; | |
32 | template <class T> | |
33 | struct has_float_types | |
92f5a8d4 | 34 | { |
1e59de90 TL |
35 | template <class U> |
36 | static double check(U*, typename U::float_types* = nullptr); | |
37 | static char check(...); | |
38 | static T* get(); | |
39 | static constexpr bool value = sizeof(check(get())) == sizeof(double); | |
92f5a8d4 TL |
40 | }; |
41 | ||
1e59de90 TL |
42 | template <class T> |
43 | struct is_backend : public std::integral_constant<bool, has_signed_types<T>::value && has_unsigned_types<T>::value && has_float_types<T>::value> {}; | |
44 | ||
92f5a8d4 TL |
45 | template <class Backend> |
46 | struct other_backend | |
47 | { | |
1e59de90 TL |
48 | using type = typename std::conditional< |
49 | std::is_same<number<Backend>, number<Backend, et_on> >::value, | |
50 | number<Backend, et_off>, number<Backend, et_on> >::type; | |
92f5a8d4 TL |
51 | }; |
52 | ||
53 | template <class B, class V> | |
54 | struct number_from_backend | |
55 | { | |
1e59de90 TL |
56 | using type = typename std::conditional< |
57 | std::is_convertible<V, number<B> >::value, | |
92f5a8d4 | 58 | number<B>, |
1e59de90 | 59 | typename other_backend<B>::type>::type; |
92f5a8d4 TL |
60 | }; |
61 | ||
62 | template <bool b, class T, class U> | |
1e59de90 TL |
63 | struct is_first_backend_imp : public std::false_type {}; |
64 | ||
92f5a8d4 | 65 | template <class T, class U> |
1e59de90 | 66 | struct is_first_backend_imp<true, T, U> : public std::integral_constant < bool, std::is_convertible<U, number<T, et_on> >::value || std::is_convertible<U, number<T, et_off> >::value> {}; |
92f5a8d4 TL |
67 | |
68 | template <class T, class U> | |
69 | struct is_first_backend : is_first_backend_imp<is_backend<T>::value, T, U> | |
70 | {}; | |
71 | ||
72 | template <bool b, class T, class U> | |
73 | struct is_second_backend_imp | |
74 | { | |
1e59de90 | 75 | static constexpr const bool value = false; |
92f5a8d4 TL |
76 | }; |
77 | template <class T, class U> | |
78 | struct is_second_backend_imp<true, T, U> | |
79 | { | |
1e59de90 | 80 | static constexpr const bool value = (std::is_convertible<T, number<U, et_on> >::value || std::is_convertible<T, number<U, et_off> >::value) && !is_first_backend<T, U>::value; |
92f5a8d4 TL |
81 | }; |
82 | ||
83 | template <class T, class U> | |
84 | struct is_second_backend : is_second_backend_imp<is_backend<U>::value, T, U> | |
85 | {}; | |
7c673cae FG |
86 | |
87 | } | |
88 | } | |
92f5a8d4 | 89 | } // namespace boost::multiprecision::detail |
7c673cae FG |
90 | |
91 | #endif // BOOST_MP_IS_BACKEND_HPP |