Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65150 - trunk/libs/math/example
From: pbristow_at_[hidden]
Date: 2010-08-31 10:05:48


Author: pbristow
Date: 2010-08-31 10:05:46 EDT (Tue, 31 Aug 2010)
New Revision: 65150
URL: http://svn.boost.org/trac/boost/changeset/65150

Log:
Avoid name ambiguity.
Text files modified:
   trunk/libs/math/example/policy_ref_snip13.cpp | 49 ++++++++++++++++++++++++++++-----------
   1 files changed, 35 insertions(+), 14 deletions(-)

Modified: trunk/libs/math/example/policy_ref_snip13.cpp
==============================================================================
--- trunk/libs/math/example/policy_ref_snip13.cpp (original)
+++ trunk/libs/math/example/policy_ref_snip13.cpp 2010-08-31 10:05:46 EDT (Tue, 31 Aug 2010)
@@ -1,4 +1,5 @@
 // Copyright John Maddock 2007.
+// Copyright Paul A. Bristow 2010
 // 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)
@@ -7,48 +8,68 @@
 // and comments, don't change any of the special comment mark-ups!
 
 #ifdef _MSC_VER
-#pragma warning (disable : 4189) // 'd' : local variable is initialized but not referenced
+# pragma warning (disable : 4189) // 'd' : local variable is initialized but not referenced
 #endif
 
+#include <iostream>
+using std::cout; using std::endl;
+
+#include <exception>
+using std::domain_error;
+
+
 //[policy_ref_snip13
 
 #include <boost/math/distributions/cauchy.hpp>
 
-namespace myspace{
+namespace myspace
+{ // using namespace boost::math::policies; // May be convenientin myspace.
 
-using namespace boost::math::policies;
+ // Define a policy called my_policy to use.
+ using boost::math::policies::policy;
+
+// In this case we want all the distribution accessor functions to compile,
+// even if they are mathematically undefined, so
+// make the policy assert_undefined.
+ using boost::math::policies::assert_undefined;
 
-// Define a policy to use, in this case we want all the distribution
-// accessor functions to compile, even if they are mathematically
-// undefined:
 typedef policy<assert_undefined<false> > my_policy;
 
+// Finally apply this policy to type double.
 BOOST_MATH_DECLARE_DISTRIBUTIONS(double, my_policy)
-
-}
+} // namespace myspace
 
 // Now we can use myspace::cauchy etc, which will use policy
 // myspace::mypolicy:
 //
-// This compiles but raises a domain error at runtime:
-//
+// This compiles but raises a domain error at runtime.
+// (Caution, if you omit the try'n'catch blocks, it will just terminate,
+// giving no clues as to why. So try'n'catch blocks are strongly recommended.
+
 void test_cauchy()
 {
    try
    {
       double d = mean(myspace::cauchy());
    }
- catch(const std::domain_error& e)
+ catch(const domain_error& e)
    {
- std::cout << e.what() << std::endl;
+ cout << e.what() << endl;
    }
 }
 
 //]
 
-#include <iostream>
-
 int main()
 {
    test_cauchy();
 }
+
+/*
+
+Output:
+
+policy_snip_13.vcxproj -> J:\Cpp\MathToolkit\test\Math_test\Release\policy_snip_13.exe
+ Error in function boost::math::mean(cauchy<double>&): The Cauchy distribution does not have a mean: the only possible return value is 1.#QNAN.
+
+ */
\ No newline at end of file


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk