]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/math/tools/traits.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / math / tools / traits.hpp
1 // Copyright John Maddock 2007.
2 // Copyright Matt Borland 2021.
3 // Use, modification and distribution are subject to the
4 // Boost 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 /*
8 This header defines two traits classes, both in namespace boost::math::tools.
9
10 is_distribution<D>::value is true iff D has overloaded "cdf" and
11 "quantile" functions, plus member typedefs value_type and policy_type.
12 It's not much of a definitive test frankly,
13 but if it looks like a distribution and quacks like a distribution
14 then it must be a distribution.
15
16 is_scaled_distribution<D>::value is true iff D is a distribution
17 as defined above, and has member functions "scale" and "location".
18
19 */
20
21 #ifndef BOOST_STATS_IS_DISTRIBUTION_HPP
22 #define BOOST_STATS_IS_DISTRIBUTION_HPP
23
24 #ifdef _MSC_VER
25 #pragma once
26 #endif
27
28 #include <type_traits>
29
30 namespace boost{ namespace math{ namespace tools{
31
32 namespace detail{
33
34 #define BOOST_MATH_HAS_NAMED_TRAIT(trait, name) \
35 template <typename T> \
36 class trait \
37 { \
38 private: \
39 using yes = char; \
40 struct no { char x[2]; }; \
41 \
42 template <typename U> \
43 static yes test(typename U::name* = nullptr); \
44 \
45 template <typename U> \
46 static no test(...); \
47 \
48 public: \
49 static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char)); \
50 };
51
52 BOOST_MATH_HAS_NAMED_TRAIT(has_value_type, value_type)
53 BOOST_MATH_HAS_NAMED_TRAIT(has_policy_type, policy_type)
54 BOOST_MATH_HAS_NAMED_TRAIT(has_backend_type, backend_type)
55
56 template <typename D>
57 char cdf(const D& ...);
58 template <typename D>
59 char quantile(const D& ...);
60
61 template <typename D>
62 struct has_cdf
63 {
64 static D d;
65 static constexpr bool value = sizeof(cdf(d, 0.0f)) != 1;
66 };
67
68 template <typename D>
69 struct has_quantile
70 {
71 static D d;
72 static constexpr bool value = sizeof(quantile(d, 0.0f)) != 1;
73 };
74
75 template <typename D>
76 struct is_distribution_imp
77 {
78 static constexpr bool value =
79 has_quantile<D>::value
80 && has_cdf<D>::value
81 && has_value_type<D>::value
82 && has_policy_type<D>::value;
83 };
84
85 template <typename sig, sig val>
86 struct result_tag{};
87
88 template <typename D>
89 double test_has_location(const volatile result_tag<typename D::value_type (D::*)()const, &D::location>*);
90 template <typename D>
91 char test_has_location(...);
92
93 template <typename D>
94 double test_has_scale(const volatile result_tag<typename D::value_type (D::*)()const, &D::scale>*);
95 template <typename D>
96 char test_has_scale(...);
97
98 template <typename D, bool b>
99 struct is_scaled_distribution_helper
100 {
101 static constexpr bool value = false;
102 };
103
104 template <typename D>
105 struct is_scaled_distribution_helper<D, true>
106 {
107 static constexpr bool value =
108 (sizeof(test_has_location<D>(0)) != 1)
109 &&
110 (sizeof(test_has_scale<D>(0)) != 1);
111 };
112
113 template <typename D>
114 struct is_scaled_distribution_imp
115 {
116 static constexpr bool value = (::boost::math::tools::detail::is_scaled_distribution_helper<D, ::boost::math::tools::detail::is_distribution_imp<D>::value>::value);
117 };
118
119 } // namespace detail
120
121 template <typename T> struct is_distribution : public std::integral_constant<bool, ::boost::math::tools::detail::is_distribution_imp<T>::value> {};
122 template <typename T> struct is_scaled_distribution : public std::integral_constant<bool, ::boost::math::tools::detail::is_scaled_distribution_imp<T>::value> {};
123
124 }}}
125
126 #endif
127
128