]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/multiprecision/traits/is_backend.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / multiprecision / traits / is_backend.hpp
CommitLineData
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
12namespace boost { namespace multiprecision { namespace detail {
13
92f5a8d4 14template <class T>
1e59de90
TL
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
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
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
92f5a8d4
TL
45template <class Backend>
46struct 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
53template <class B, class V>
54struct 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
62template <bool b, class T, class U>
1e59de90
TL
63struct is_first_backend_imp : public std::false_type {};
64
92f5a8d4 65template <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
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{
1e59de90 75 static constexpr const bool value = false;
92f5a8d4
TL
76};
77template <class T, class U>
78struct 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
83template <class T, class U>
84struct 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