1 // Copyright John Maddock 2007.
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)
8 This header defines two traits classes, both in namespace boost::math::tools.
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.
16 is_scaled_distribution<D>::value is true iff D is a distribution
17 as defined above, and has member functions "scale" and "location".
21 #ifndef BOOST_STATS_IS_DISTRIBUTION_HPP
22 #define BOOST_STATS_IS_DISTRIBUTION_HPP
28 #include <boost/mpl/has_xxx.hpp>
29 #include <boost/type_traits/integral_constant.hpp>
31 namespace boost{ namespace math{ namespace tools{
35 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_value_type, value_type, true)
36 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_policy_type, policy_type, true)
37 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_backend_type, backend_type, true)
40 char cdf(const D& ...);
42 char quantile(const D& ...);
48 BOOST_STATIC_CONSTANT(bool, value = sizeof(cdf(d, 0.0f)) != 1);
55 BOOST_STATIC_CONSTANT(bool, value = sizeof(quantile(d, 0.0f)) != 1);
59 struct is_distribution_imp
61 BOOST_STATIC_CONSTANT(bool, value =
62 has_quantile<D>::value
64 && has_value_type<D>::value
65 && has_policy_type<D>::value);
68 template <class sig, sig val>
72 double test_has_location(const volatile result_tag<typename D::value_type (D::*)()const, &D::location>*);
74 char test_has_location(...);
77 double test_has_scale(const volatile result_tag<typename D::value_type (D::*)()const, &D::scale>*);
79 char test_has_scale(...);
81 template <class D, bool b>
82 struct is_scaled_distribution_helper
84 BOOST_STATIC_CONSTANT(bool, value = false);
88 struct is_scaled_distribution_helper<D, true>
90 BOOST_STATIC_CONSTANT(bool, value =
91 (sizeof(test_has_location<D>(0)) != 1)
93 (sizeof(test_has_scale<D>(0)) != 1));
97 struct is_scaled_distribution_imp
99 BOOST_STATIC_CONSTANT(bool, value = (::boost::math::tools::detail::is_scaled_distribution_helper<D, ::boost::math::tools::detail::is_distribution_imp<D>::value>::value));
102 } // namespace detail
104 template <class T> struct is_distribution : public boost::integral_constant<bool, ::boost::math::tools::detail::is_distribution_imp<T>::value> {};
105 template <class T> struct is_scaled_distribution : public boost::integral_constant<bool, ::boost::math::tools::detail::is_scaled_distribution_imp<T>::value> {};