]>
git.proxmox.com Git - ceph.git/blob - 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)
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!
11 # pragma warning (disable : 4189) // 'd' : local variable is initialized but not referenced
15 using std::cout
; using std::endl
;
18 using std::domain_error
;
22 #include <boost/math/distributions/cauchy.hpp>
25 { // using namespace boost::math::policies; // May be convenient in myspace.
27 // Define a policy called my_policy to use.
28 using boost::math::policies::policy
;
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
;
35 typedef policy
<assert_undefined
<false> > my_policy
;
37 // Finally apply this policy to type double.
38 BOOST_MATH_DECLARE_DISTRIBUTIONS(double, my_policy
)
39 } // namespace myspace
41 // Now we can use myspace::cauchy etc, which will use policy
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.
53 double d
= mean(myspace::cauchy()); // Cauchy does not have a mean!
55 catch(const std::domain_error
& e
)
57 cout
<< e
.what() << endl
;
61 //] //[/policy_ref_snip13]
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.