File indexing completed on 2025-01-18 09:42:24
0001
0002
0003
0004
0005
0006 #ifndef BOOST_MP_IS_BACKEND_HPP
0007 #define BOOST_MP_IS_BACKEND_HPP
0008
0009 #include <type_traits>
0010 #include <boost/multiprecision/detail/number_base.hpp>
0011
0012 namespace boost { namespace multiprecision { namespace detail {
0013
0014 template <class T>
0015 struct has_signed_types
0016 {
0017 template <class U>
0018 static double check(U*, typename U::signed_types* = nullptr);
0019 static char check(...);
0020 static T* get();
0021 static constexpr bool value = sizeof(check(get())) == sizeof(double);
0022 };
0023 template <class T>
0024 struct has_unsigned_types
0025 {
0026 template <class U>
0027 static double check(U*, typename U::unsigned_types* = nullptr);
0028 static char check(...);
0029 static T* get();
0030 static constexpr bool value = sizeof(check(get())) == sizeof(double);
0031 };
0032 template <class T>
0033 struct has_float_types
0034 {
0035 template <class U>
0036 static double check(U*, typename U::float_types* = nullptr);
0037 static char check(...);
0038 static T* get();
0039 static constexpr bool value = sizeof(check(get())) == sizeof(double);
0040 };
0041
0042 template <class T>
0043 struct is_backend : public std::integral_constant<bool, has_signed_types<T>::value && has_unsigned_types<T>::value && has_float_types<T>::value> {};
0044
0045 template <class Backend>
0046 struct other_backend
0047 {
0048 using type = typename std::conditional<
0049 std::is_same<number<Backend>, number<Backend, et_on> >::value,
0050 number<Backend, et_off>, number<Backend, et_on> >::type;
0051 };
0052
0053 template <class B, class V>
0054 struct number_from_backend
0055 {
0056 using type = typename std::conditional<
0057 std::is_convertible<V, number<B> >::value,
0058 number<B>,
0059 typename other_backend<B>::type>::type;
0060 };
0061
0062 template <bool b, class T, class U>
0063 struct is_first_backend_imp : public std::false_type {};
0064
0065 template <class T, class U>
0066 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> {};
0067
0068 template <class T, class U>
0069 struct is_first_backend : is_first_backend_imp<is_backend<T>::value, T, U>
0070 {};
0071
0072 template <bool b, class T, class U>
0073 struct is_second_backend_imp
0074 {
0075 static constexpr bool value = false;
0076 };
0077 template <class T, class U>
0078 struct is_second_backend_imp<true, T, U>
0079 {
0080 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;
0081 };
0082
0083 template <class T, class U>
0084 struct is_second_backend : is_second_backend_imp<is_backend<U>::value, T, U>
0085 {};
0086
0087 }
0088 }
0089 }
0090
0091 #endif