Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71415 - trunk/libs/math/example
From: pbristow_at_[hidden]
Date: 2011-04-22 05:56:32


Author: pbristow
Date: 2011-04-22 05:56:31 EDT (Fri, 22 Apr 2011)
New Revision: 71415
URL: http://svn.boost.org/trac/boost/changeset/71415

Log:
Added example of concise imbue of cout and cin.
Text files modified:
   trunk/libs/math/example/nonfinite_facet_simple.cpp | 14 +++++++++++---
   1 files changed, 11 insertions(+), 3 deletions(-)

Modified: trunk/libs/math/example/nonfinite_facet_simple.cpp
==============================================================================
--- trunk/libs/math/example/nonfinite_facet_simple.cpp (original)
+++ trunk/libs/math/example/nonfinite_facet_simple.cpp 2011-04-22 05:56:31 EDT (Fri, 22 Apr 2011)
@@ -46,6 +46,10 @@
 using std::istringstream;
 
 #include <limits>
+using std::numeric_limits;
+
+#include <locale>
+using std::locale;
 
 #include <boost/math/special_functions/nonfinite_num_facets.hpp>
 // from Johan Rade Floating Point Utilities.
@@ -75,7 +79,10 @@
   std::locale C99_out_locale (default_locale, new boost::math::nonfinite_num_put<char>);
   // and imbue the cout stream with the new locale.
   cout.imbue (C99_out_locale);
-
+
+ // Or for the same effect more concisely:
+ cout.imbue (locale(locale(), new boost::math::nonfinite_num_put<char>));
+
   // Output using the new locale
   cout << "Using C99_out_locale " << endl;
   cout << "+std::numeric_limits<double>::infinity() = " << plus_infinity << endl;
@@ -104,9 +111,10 @@
   { // Now retry using C99 facets.
   // Create a new input locale and add the nonfinite_num_get facet.
   std::locale C99_in_locale (default_locale, new boost::math::nonfinite_num_get<char>);
- // imbue the stream with the C99 input locale.
- // Create an input stream which will provide "inf"
+
+ // Create an input stream which will provide "inf".
   std::istringstream iss (inf);
+ // Imbue the stream with the C99 input locale.
   iss.imbue (C99_in_locale);
 
   // Create a double ready to take the input,


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