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
9#include <type_traits>
10#include <boost/multiprecision/detail/number_base.hpp>
11
12namespace boost { namespace multiprecision { namespace detail {
13
14template <class T>
15struct 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};
23template <class T>
24struct 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};
32template <class T>
33struct has_float_types
34{
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);
40};
41
42template <class T>
43struct is_backend : public std::integral_constant<bool, has_signed_types<T>::value && has_unsigned_types<T>::value && has_float_types<T>::value> {};
44
45template <class Backend>
46struct other_backend
47{
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;
51};
52
53template <class B, class V>
54struct number_from_backend
55{
56 using type = typename std::conditional<
57 std::is_convertible<V, number<B> >::value,
58 number<B>,
59 typename other_backend<B>::type>::type;
60};
61
62template <bool b, class T, class U>
63struct is_first_backend_imp : public std::false_type {};
64
65template <class T, class U>
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> {};
67
68template <class T, class U>
69struct is_first_backend : is_first_backend_imp<is_backend<T>::value, T, U>
70{};
71
72template <bool b, class T, class U>
73struct is_second_backend_imp
74{
75 static constexpr bool value = false;
76};
77template <class T, class U>
78struct is_second_backend_imp<true, T, U>
79{
80 static constexpr 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;
81};
82
83template <class T, class U>
84struct is_second_backend : is_second_backend_imp<is_backend<U>::value, T, U>
85{};
86
87}
88}
89} // namespace boost::multiprecision::detail
90
91#endif // BOOST_MP_IS_BACKEND_HPP
92

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