// Copyright John Maddock 2007. // 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) // // Note this header must NOT include any other headers, for its // use to be meaningful (because we use it in tests designed to // detect missing includes). // static const float f = 0; static const double d = 0; static const long double l = 0; static const unsigned u = 0; static const int i = 0; //template //inline void check_result_imp(T, T){} inline void check_result_imp(float, float){} inline void check_result_imp(double, double){} inline void check_result_imp(long double, long double){} inline void check_result_imp(int, int){} inline void check_result_imp(long, long){} #ifdef BOOST_HAS_LONG_LONG inline void check_result_imp(boost::long_long_type, boost::long_long_type){} #endif inline void check_result_imp(bool, bool){} // // If the compiler warns about unused typedefs then enable this: // #if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7))) # define BOOST_MATH_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused)) #else # define BOOST_MATH_ASSERT_UNUSED_ATTRIBUTE #endif template struct local_is_same { enum{ value = false }; }; template struct local_is_same { enum{ value = true }; }; template inline void check_result_imp(T1, T2) { // This is a static assertion that should always fail to compile... #if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-local-typedefs" #endif typedef BOOST_MATH_ASSERT_UNUSED_ATTRIBUTE int static_assertion[local_is_same::value ? 1 : 0]; #if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))) #pragma GCC diagnostic pop #endif } template inline void check_result(T2) { T1 a = T1(); T2 b = T2(); return check_result_imp(a, b); } union max_align_type { char c; short s; int i; long l; double d; long double ld; #ifdef BOOST_HAS_LONG_LONG long long ll; #endif }; template struct DistributionConcept { static void constraints() { typedef typename Distribution::value_type value_type; const Distribution& dist = DistributionConcept::get_object(); value_type x = 0; // The result values are ignored in all these checks. check_result(cdf(dist, x)); check_result(cdf(complement(dist, x))); check_result(pdf(dist, x)); check_result(quantile(dist, x)); check_result(quantile(complement(dist, x))); check_result(mean(dist)); check_result(mode(dist)); check_result(standard_deviation(dist)); check_result(variance(dist)); check_result(hazard(dist, x)); check_result(chf(dist, x)); check_result(coefficient_of_variation(dist)); check_result(skewness(dist)); check_result(kurtosis(dist)); check_result(kurtosis_excess(dist)); check_result(median(dist)); // // we can't actually test that at std::pair is returned from these // because that would mean including some std lib headers.... // range(dist); support(dist); check_result(cdf(dist, f)); check_result(cdf(complement(dist, f))); check_result(pdf(dist, f)); check_result(quantile(dist, f)); check_result(quantile(complement(dist, f))); check_result(hazard(dist, f)); check_result(chf(dist, f)); check_result(cdf(dist, d)); check_result(cdf(complement(dist, d))); check_result(pdf(dist, d)); check_result(quantile(dist, d)); check_result(quantile(complement(dist, d))); check_result(hazard(dist, d)); check_result(chf(dist, d)); check_result(cdf(dist, l)); check_result(cdf(complement(dist, l))); check_result(pdf(dist, l)); check_result(quantile(dist, l)); check_result(quantile(complement(dist, l))); check_result(hazard(dist, l)); check_result(chf(dist, l)); check_result(cdf(dist, i)); check_result(cdf(complement(dist, i))); check_result(pdf(dist, i)); check_result(quantile(dist, i)); check_result(quantile(complement(dist, i))); check_result(hazard(dist, i)); check_result(chf(dist, i)); unsigned long li = 1; check_result(cdf(dist, li)); check_result(cdf(complement(dist, li))); check_result(pdf(dist, li)); check_result(quantile(dist, li)); check_result(quantile(complement(dist, li))); check_result(hazard(dist, li)); check_result(chf(dist, li)); } private: static void* storage() { static max_align_type storage[sizeof(Distribution)]; return storage; } static Distribution* get_object_p() { return static_cast(storage()); } static Distribution& get_object() { // will never get called: return *get_object_p(); } }; // struct DistributionConcept #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS #define TEST_DIST_FUNC(dist)\ DistributionConcept< boost::math::dist##_distribution >::constraints();\ DistributionConcept< boost::math::dist##_distribution >::constraints();\ DistributionConcept< boost::math::dist##_distribution >::constraints(); #else #define TEST_DIST_FUNC(dist)\ DistributionConcept< boost::math::dist##_distribution >::constraints();\ DistributionConcept< boost::math::dist##_distribution >::constraints(); #endif