]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/test/compile_test/test_compile_result.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / math / test / compile_test / test_compile_result.hpp
1 // Copyright John Maddock 2007.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 //
7 // Note this header must NOT include any other headers, for its
8 // use to be meaningful (because we use it in tests designed to
9 // detect missing includes).
10 //
11
12 static const float f = 0;
13 static const double d = 0;
14 static const long double l = 0;
15 static const unsigned u = 0;
16 static const int i = 0;
17
18 //template <class T>
19 //inline void check_result_imp(T, T){}
20
21 inline void check_result_imp(float, float){}
22 inline void check_result_imp(double, double){}
23 inline void check_result_imp(long double, long double){}
24 inline void check_result_imp(int, int){}
25 inline void check_result_imp(long, long){}
26 #ifdef BOOST_HAS_LONG_LONG
27 inline void check_result_imp(boost::long_long_type, boost::long_long_type){}
28 #endif
29 inline void check_result_imp(bool, bool){}
30
31 //
32 // If the compiler warns about unused typedefs then enable this:
33 //
34 #if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)))
35 # define BOOST_MATH_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused))
36 #else
37 # define BOOST_MATH_ASSERT_UNUSED_ATTRIBUTE
38 #endif
39
40 template <class T, class U>
41 struct local_is_same
42 {
43 enum{ value = false };
44 };
45 template <class T>
46 struct local_is_same<T, T>
47 {
48 enum{ value = true };
49 };
50
51 template <class T1, class T2>
52 inline void check_result_imp(T1, T2)
53 {
54 // This is a static assertion that should always fail to compile...
55 typedef BOOST_MATH_ASSERT_UNUSED_ATTRIBUTE int static_assertion[local_is_same<T1, T2>::value ? 1 : 0];
56 }
57
58 template <class T1, class T2>
59 inline void check_result(T2)
60 {
61 T1 a = T1();
62 T2 b = T2();
63 return check_result_imp(a, b);
64 }
65
66 union max_align_type
67 {
68 char c;
69 short s;
70 int i;
71 long l;
72 double d;
73 long double ld;
74 #ifdef BOOST_HAS_LONG_LONG
75 long long ll;
76 #endif
77 };
78
79 template <class Distribution>
80 struct DistributionConcept
81 {
82 static void constraints()
83 {
84 typedef typename Distribution::value_type value_type;
85
86 const Distribution& dist = DistributionConcept<Distribution>::get_object();
87
88 value_type x = 0;
89 // The result values are ignored in all these checks.
90 check_result<value_type>(cdf(dist, x));
91 check_result<value_type>(cdf(complement(dist, x)));
92 check_result<value_type>(pdf(dist, x));
93 check_result<value_type>(quantile(dist, x));
94 check_result<value_type>(quantile(complement(dist, x)));
95 check_result<value_type>(mean(dist));
96 check_result<value_type>(mode(dist));
97 check_result<value_type>(standard_deviation(dist));
98 check_result<value_type>(variance(dist));
99 check_result<value_type>(hazard(dist, x));
100 check_result<value_type>(chf(dist, x));
101 check_result<value_type>(coefficient_of_variation(dist));
102 check_result<value_type>(skewness(dist));
103 check_result<value_type>(kurtosis(dist));
104 check_result<value_type>(kurtosis_excess(dist));
105 check_result<value_type>(median(dist));
106 //
107 // we can't actually test that at std::pair is returned from these
108 // because that would mean including some std lib headers....
109 //
110 range(dist);
111 support(dist);
112
113 check_result<value_type>(cdf(dist, f));
114 check_result<value_type>(cdf(complement(dist, f)));
115 check_result<value_type>(pdf(dist, f));
116 check_result<value_type>(quantile(dist, f));
117 check_result<value_type>(quantile(complement(dist, f)));
118 check_result<value_type>(hazard(dist, f));
119 check_result<value_type>(chf(dist, f));
120 check_result<value_type>(cdf(dist, d));
121 check_result<value_type>(cdf(complement(dist, d)));
122 check_result<value_type>(pdf(dist, d));
123 check_result<value_type>(quantile(dist, d));
124 check_result<value_type>(quantile(complement(dist, d)));
125 check_result<value_type>(hazard(dist, d));
126 check_result<value_type>(chf(dist, d));
127 check_result<value_type>(cdf(dist, l));
128 check_result<value_type>(cdf(complement(dist, l)));
129 check_result<value_type>(pdf(dist, l));
130 check_result<value_type>(quantile(dist, l));
131 check_result<value_type>(quantile(complement(dist, l)));
132 check_result<value_type>(hazard(dist, l));
133 check_result<value_type>(chf(dist, l));
134 check_result<value_type>(cdf(dist, i));
135 check_result<value_type>(cdf(complement(dist, i)));
136 check_result<value_type>(pdf(dist, i));
137 check_result<value_type>(quantile(dist, i));
138 check_result<value_type>(quantile(complement(dist, i)));
139 check_result<value_type>(hazard(dist, i));
140 check_result<value_type>(chf(dist, i));
141 unsigned long li = 1;
142 check_result<value_type>(cdf(dist, li));
143 check_result<value_type>(cdf(complement(dist, li)));
144 check_result<value_type>(pdf(dist, li));
145 check_result<value_type>(quantile(dist, li));
146 check_result<value_type>(quantile(complement(dist, li)));
147 check_result<value_type>(hazard(dist, li));
148 check_result<value_type>(chf(dist, li));
149 }
150 private:
151 static void* storage()
152 {
153 static max_align_type storage[sizeof(Distribution)];
154 return storage;
155 }
156 static Distribution* get_object_p()
157 {
158 return static_cast<Distribution*>(storage());
159 }
160 static Distribution& get_object()
161 {
162 // will never get called:
163 return *get_object_p();
164 }
165 }; // struct DistributionConcept
166
167 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
168 #define TEST_DIST_FUNC(dist)\
169 DistributionConcept< boost::math::dist##_distribution<float> >::constraints();\
170 DistributionConcept< boost::math::dist##_distribution<double> >::constraints();\
171 DistributionConcept< boost::math::dist##_distribution<long double> >::constraints();
172 #else
173 #define TEST_DIST_FUNC(dist)\
174 DistributionConcept< boost::math::dist##_distribution<float> >::constraints();\
175 DistributionConcept< boost::math::dist##_distribution<double> >::constraints();
176 #endif