Chris@16: // Copyright John Maddock 2007. Chris@16: Chris@16: // Use, modification and distribution are subject to the Chris@16: // Boost Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: /* Chris@16: This header defines two traits classes, both in namespace boost::math::tools. Chris@16: Chris@16: is_distribution::value is true iff D has overloaded "cdf" and Chris@16: "quantile" functions, plus member typedefs value_type and policy_type. Chris@16: It's not much of a definitive test frankly, Chris@16: but if it looks like a distribution and quacks like a distribution Chris@16: then it must be a distribution. Chris@16: Chris@16: is_scaled_distribution::value is true iff D is a distribution Chris@16: as defined above, and has member functions "scale" and "location". Chris@16: Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_STATS_IS_DISTRIBUTION_HPP Chris@16: #define BOOST_STATS_IS_DISTRIBUTION_HPP Chris@16: Chris@16: #ifdef _MSC_VER Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: // should be the last #include Chris@16: #include Chris@16: Chris@16: namespace boost{ namespace math{ namespace tools{ Chris@16: Chris@16: namespace detail{ Chris@16: Chris@16: BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_value_type, value_type, true) Chris@16: BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_policy_type, policy_type, true) Chris@16: Chris@16: template Chris@16: char cdf(const D& ...); Chris@16: template Chris@16: char quantile(const D& ...); Chris@16: Chris@16: template Chris@16: struct has_cdf Chris@16: { Chris@16: static D d; Chris@16: BOOST_STATIC_CONSTANT(bool, value = sizeof(cdf(d, 0.0f)) != 1); Chris@16: }; Chris@16: Chris@16: template Chris@16: struct has_quantile Chris@16: { Chris@16: static D d; Chris@16: BOOST_STATIC_CONSTANT(bool, value = sizeof(quantile(d, 0.0f)) != 1); Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_distribution_imp Chris@16: { Chris@16: BOOST_STATIC_CONSTANT(bool, value = Chris@16: has_quantile::value Chris@16: && has_cdf::value Chris@16: && has_value_type::value Chris@16: && has_policy_type::value); Chris@16: }; Chris@16: Chris@16: template Chris@16: struct result_tag{}; Chris@16: Chris@16: template Chris@16: double test_has_location(const volatile result_tag*); Chris@16: template Chris@16: char test_has_location(...); Chris@16: Chris@16: template Chris@16: double test_has_scale(const volatile result_tag*); Chris@16: template Chris@16: char test_has_scale(...); Chris@16: Chris@16: template Chris@16: struct is_scaled_distribution_helper Chris@16: { Chris@16: BOOST_STATIC_CONSTANT(bool, value = false); Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_scaled_distribution_helper Chris@16: { Chris@16: BOOST_STATIC_CONSTANT(bool, value = Chris@16: (sizeof(test_has_location(0)) != 1) Chris@16: && Chris@16: (sizeof(test_has_scale(0)) != 1)); Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_scaled_distribution_imp Chris@16: { Chris@16: BOOST_STATIC_CONSTANT(bool, value = (::boost::math::tools::detail::is_scaled_distribution_helper::value>::value)); Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: Chris@16: BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_distribution,T,::boost::math::tools::detail::is_distribution_imp::value) Chris@16: BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_scaled_distribution,T,::boost::math::tools::detail::is_scaled_distribution_imp::value) Chris@16: Chris@16: }}} Chris@16: Chris@16: #endif Chris@16: Chris@16: