]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/example/policy_ref_snip13.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / math / example / policy_ref_snip13.cpp
1 // Copyright John Maddock 2007.
2 // Copyright Paul A. Bristow 2010
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)
6
7 // Note that this file contains quickbook mark-up as well as code
8 // and comments, don't change any of the special comment mark-ups!
9
10 #ifdef _MSC_VER
11 # pragma warning (disable : 4189) // 'd' : local variable is initialized but not referenced
12 #endif
13
14 #include <iostream>
15 using std::cout; using std::endl;
16
17 #include <stdexcept>
18 using std::domain_error;
19
20 //[policy_ref_snip13
21
22 #include <boost/math/distributions/cauchy.hpp>
23
24 namespace myspace
25 { // using namespace boost::math::policies; // May be convenient in myspace.
26
27 // Define a policy called my_policy to use.
28 using boost::math::policies::policy;
29
30 // In this case we want all the distribution accessor functions to compile,
31 // even if they are mathematically undefined, so
32 // make the policy assert_undefined.
33 using boost::math::policies::assert_undefined;
34
35 typedef policy<assert_undefined<false> > my_policy;
36
37 // Finally apply this policy to type double.
38 BOOST_MATH_DECLARE_DISTRIBUTIONS(double, my_policy)
39 } // namespace myspace
40
41 // Now we can use myspace::cauchy etc, which will use policy
42 // myspace::mypolicy:
43 //
44 // This compiles but throws a domain error exception at runtime.
45 // Caution! If you omit the try'n'catch blocks,
46 // it will just silently terminate, giving no clues as to why!
47 // So try'n'catch blocks are very strongly recommended.
48
49 void test_cauchy()
50 {
51 try
52 {
53 double d = mean(myspace::cauchy()); // Cauchy does not have a mean!
54 }
55 catch(const std::domain_error& e)
56 {
57 cout << e.what() << endl;
58 }
59 }
60
61 //] //[/policy_ref_snip13]
62
63 int main()
64 {
65 test_cauchy();
66 }
67
68 /*
69
70 Output:
71
72 policy_snip_13.vcxproj -> J:\Cpp\MathToolkit\test\Math_test\Release\policy_snip_13.exe
73 Error in function boost::math::mean(cauchy<double>&): The Cauchy distribution does not have a mean: the only possible return value is 1.#QNAN.
74
75 */
76