]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/math/include/boost/math/tools/traits.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / math / include / boost / math / tools / traits.hpp
CommitLineData
7c673cae
FG
1// Copyright John Maddock 2007.
2
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/*
8This header defines two traits classes, both in namespace boost::math::tools.
9
10is_distribution<D>::value is true iff D has overloaded "cdf" and
11"quantile" functions, plus member typedefs value_type and policy_type.
12It's not much of a definitive test frankly,
13but if it looks like a distribution and quacks like a distribution
14then it must be a distribution.
15
16is_scaled_distribution<D>::value is true iff D is a distribution
17as 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 <boost/mpl/has_xxx.hpp>
29#include <boost/type_traits/integral_constant.hpp>
30
31namespace boost{ namespace math{ namespace tools{
32
33namespace detail{
34
35BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_value_type, value_type, true)
36BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_policy_type, policy_type, true)
37
38template<class D>
39char cdf(const D& ...);
40template<class D>
41char quantile(const D& ...);
42
43template <class D>
44struct has_cdf
45{
46 static D d;
47 BOOST_STATIC_CONSTANT(bool, value = sizeof(cdf(d, 0.0f)) != 1);
48};
49
50template <class D>
51struct has_quantile
52{
53 static D d;
54 BOOST_STATIC_CONSTANT(bool, value = sizeof(quantile(d, 0.0f)) != 1);
55};
56
57template <class D>
58struct is_distribution_imp
59{
60 BOOST_STATIC_CONSTANT(bool, value =
61 has_quantile<D>::value
62 && has_cdf<D>::value
63 && has_value_type<D>::value
64 && has_policy_type<D>::value);
65};
66
67template <class sig, sig val>
68struct result_tag{};
69
70template <class D>
71double test_has_location(const volatile result_tag<typename D::value_type (D::*)()const, &D::location>*);
72template <class D>
73char test_has_location(...);
74
75template <class D>
76double test_has_scale(const volatile result_tag<typename D::value_type (D::*)()const, &D::scale>*);
77template <class D>
78char test_has_scale(...);
79
80template <class D, bool b>
81struct is_scaled_distribution_helper
82{
83 BOOST_STATIC_CONSTANT(bool, value = false);
84};
85
86template <class D>
87struct is_scaled_distribution_helper<D, true>
88{
89 BOOST_STATIC_CONSTANT(bool, value =
90 (sizeof(test_has_location<D>(0)) != 1)
91 &&
92 (sizeof(test_has_scale<D>(0)) != 1));
93};
94
95template <class D>
96struct is_scaled_distribution_imp
97{
98 BOOST_STATIC_CONSTANT(bool, value = (::boost::math::tools::detail::is_scaled_distribution_helper<D, ::boost::math::tools::detail::is_distribution_imp<D>::value>::value));
99};
100
101} // namespace detail
102
103template <class T> struct is_distribution : public boost::integral_constant<bool, ::boost::math::tools::detail::is_distribution_imp<T>::value> {};
104template <class T> struct is_scaled_distribution : public boost::integral_constant<bool, ::boost::math::tools::detail::is_scaled_distribution_imp<T>::value> {};
105
106}}}
107
108#endif
109
110