File indexing completed on 2025-01-18 09:40:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #ifndef BOOST_STATS_IS_DISTRIBUTION_HPP
0022 #define BOOST_STATS_IS_DISTRIBUTION_HPP
0023
0024 #ifdef _MSC_VER
0025 #pragma once
0026 #endif
0027
0028 #include <type_traits>
0029
0030 namespace boost{ namespace math{ namespace tools{
0031
0032 namespace detail{
0033
0034 #define BOOST_MATH_HAS_NAMED_TRAIT(trait, name) \
0035 template <typename T> \
0036 class trait \
0037 { \
0038 private: \
0039 using yes = char; \
0040 struct no { char x[2]; }; \
0041 \
0042 template <typename U> \
0043 static yes test(typename U::name* = nullptr); \
0044 \
0045 template <typename U> \
0046 static no test(...); \
0047 \
0048 public: \
0049 static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char)); \
0050 };
0051
0052 BOOST_MATH_HAS_NAMED_TRAIT(has_value_type, value_type)
0053 BOOST_MATH_HAS_NAMED_TRAIT(has_policy_type, policy_type)
0054 BOOST_MATH_HAS_NAMED_TRAIT(has_backend_type, backend_type)
0055
0056
0057 #if defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304L
0058 template <typename T>
0059 constexpr bool has_value_type_v = has_value_type<T>::value;
0060
0061 template <typename T>
0062 constexpr bool has_policy_type_v = has_policy_type<T>::value;
0063
0064 template <typename T>
0065 constexpr bool has_backend_type_v = has_backend_type<T>::value;
0066 #endif
0067
0068 template <typename D>
0069 char cdf(const D& ...);
0070 template <typename D>
0071 char quantile(const D& ...);
0072
0073 template <typename D>
0074 struct has_cdf
0075 {
0076 static D d;
0077 static constexpr bool value = sizeof(cdf(d, 0.0f)) != 1;
0078 };
0079
0080 template <typename D>
0081 struct has_quantile
0082 {
0083 static D d;
0084 static constexpr bool value = sizeof(quantile(d, 0.0f)) != 1;
0085 };
0086
0087 template <typename D>
0088 struct is_distribution_imp
0089 {
0090 static constexpr bool value =
0091 has_quantile<D>::value
0092 && has_cdf<D>::value
0093 && has_value_type<D>::value
0094 && has_policy_type<D>::value;
0095 };
0096
0097 template <typename sig, sig val>
0098 struct result_tag{};
0099
0100 template <typename D>
0101 double test_has_location(const volatile result_tag<typename D::value_type (D::*)()const, &D::location>*);
0102 template <typename D>
0103 char test_has_location(...);
0104
0105 template <typename D>
0106 double test_has_scale(const volatile result_tag<typename D::value_type (D::*)()const, &D::scale>*);
0107 template <typename D>
0108 char test_has_scale(...);
0109
0110 template <typename D, bool b>
0111 struct is_scaled_distribution_helper
0112 {
0113 static constexpr bool value = false;
0114 };
0115
0116 template <typename D>
0117 struct is_scaled_distribution_helper<D, true>
0118 {
0119 static constexpr bool value =
0120 (sizeof(test_has_location<D>(0)) != 1)
0121 &&
0122 (sizeof(test_has_scale<D>(0)) != 1);
0123 };
0124
0125 template <typename D>
0126 struct is_scaled_distribution_imp
0127 {
0128 static constexpr bool value = (::boost::math::tools::detail::is_scaled_distribution_helper<D, ::boost::math::tools::detail::is_distribution_imp<D>::value>::value);
0129 };
0130
0131 }
0132
0133 template <typename T> struct is_distribution : public std::integral_constant<bool, ::boost::math::tools::detail::is_distribution_imp<T>::value> {};
0134 template <typename T> struct is_scaled_distribution : public std::integral_constant<bool, ::boost::math::tools::detail::is_scaled_distribution_imp<T>::value> {};
0135
0136 }}}
0137
0138 #endif
0139
0140