// Copyright John Maddock 2007. // Copyright Matt Borland 2021. // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) /* This header defines two traits classes, both in namespace boost::math::tools. is_distribution::value is true iff D has overloaded "cdf" and "quantile" functions, plus member typedefs value_type and policy_type. It's not much of a definitive test frankly, but if it looks like a distribution and quacks like a distribution then it must be a distribution. is_scaled_distribution::value is true iff D is a distribution as defined above, and has member functions "scale" and "location". */ #ifndef BOOST_STATS_IS_DISTRIBUTION_HPP #define BOOST_STATS_IS_DISTRIBUTION_HPP #ifdef _MSC_VER #pragma once #endif #include namespace boost{ namespace math{ namespace tools{ namespace detail{ #define BOOST_MATH_HAS_NAMED_TRAIT(trait, name) \ template \ class trait \ { \ private: \ using yes = char; \ struct no { char x[2]; }; \ \ template \ static yes test(typename U::name* = nullptr); \ \ template \ static no test(...); \ \ public: \ static constexpr bool value = (sizeof(test(0)) == sizeof(char)); \ }; BOOST_MATH_HAS_NAMED_TRAIT(has_value_type, value_type) BOOST_MATH_HAS_NAMED_TRAIT(has_policy_type, policy_type) BOOST_MATH_HAS_NAMED_TRAIT(has_backend_type, backend_type) template char cdf(const D& ...); template char quantile(const D& ...); template struct has_cdf { static D d; static constexpr bool value = sizeof(cdf(d, 0.0f)) != 1; }; template struct has_quantile { static D d; static constexpr bool value = sizeof(quantile(d, 0.0f)) != 1; }; template struct is_distribution_imp { static constexpr bool value = has_quantile::value && has_cdf::value && has_value_type::value && has_policy_type::value; }; template struct result_tag{}; template double test_has_location(const volatile result_tag*); template char test_has_location(...); template double test_has_scale(const volatile result_tag*); template char test_has_scale(...); template struct is_scaled_distribution_helper { static constexpr bool value = false; }; template struct is_scaled_distribution_helper { static constexpr bool value = (sizeof(test_has_location(0)) != 1) && (sizeof(test_has_scale(0)) != 1); }; template struct is_scaled_distribution_imp { static constexpr bool value = (::boost::math::tools::detail::is_scaled_distribution_helper::value>::value); }; } // namespace detail template struct is_distribution : public std::integral_constant::value> {}; template struct is_scaled_distribution : public std::integral_constant::value> {}; }}} #endif