|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r72767 - sandbox/conversion/libs/conversion_ext/example
From: vicente.botet_at_[hidden]
Date: 2011-06-26 15:49:26
Author: viboes
Date: 2011-06-26 15:49:25 EDT (Sun, 26 Jun 2011)
New Revision: 72767
URL: http://svn.boost.org/trac/boost/changeset/72767
Log:
Conversion: warning removal
Added:
sandbox/conversion/libs/conversion_ext/example/formatted.cpp (contents, props changed)
Text files modified:
sandbox/conversion/libs/conversion_ext/example/fallback.cpp | 1 +
sandbox/conversion/libs/conversion_ext/example/no_throw.cpp | 2 --
2 files changed, 1 insertions(+), 2 deletions(-)
Modified: sandbox/conversion/libs/conversion_ext/example/fallback.cpp
==============================================================================
--- sandbox/conversion/libs/conversion_ext/example/fallback.cpp (original)
+++ sandbox/conversion/libs/conversion_ext/example/fallback.cpp 2011-06-26 15:49:25 EDT (Sun, 26 Jun 2011)
@@ -30,6 +30,7 @@
//[FALLBACK_CPP_CONVERT_TO_OR_FALLBACK
int t = convert_to_or_fallback<int>(str,-1);
//]
+ (void)t;// remove warning: unused variable
}
int main()
Added: sandbox/conversion/libs/conversion_ext/example/formatted.cpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/libs/conversion_ext/example/formatted.cpp 2011-06-26 15:49:25 EDT (Sun, 26 Jun 2011)
@@ -0,0 +1,66 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-2009. Distributed under 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)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+//[EVEN_CPP
+
+ #include <boost/conversion/extractor.hpp>
+ #include <boost/conversion/std/string.hpp>
+ #include <boost/conversion/convert_to_or_fallback.hpp>
+ #include <strstream>
+ #include <iostream>
+ #include <string>
+ #include <iomanip>
+ #include <boost/assert.hpp>
+ using namespace boost::conversion;
+
+ int main()
+ {
+ std::string hex_str = "FF"; // 255 in decimal
+ std::stringstream ios;
+
+ // This call fails
+ int bad = convert_to_or_fallback<int>(hex_str, -1);
+ BOOST_ASSERT(bad == -1); // Failed decimal conversion from "FF"
+
+ // Apply hex formatting while converting from string
+ int i = convert_to<int>(extractor<int>(
+ (ios.clear(), ios << hex_str, ios >> std::hex)));
+ BOOST_ASSERT(i == 255); // Successful hex conversion from "FF"
+
+ // Apply hex formatting while converting from string
+
+ int ii = convert_to<int>(extractor_stream<int>() << hex_str >> std::hex >> extract);
+ BOOST_ASSERT(ii == 255); // Successful hex conversion from "FF"
+
+ int iii = convert_to<int>(extractor_stream<int>() << hex_str >> std::hex);
+ BOOST_ASSERT(iii == 255); // Successful hex conversion from "FF"
+
+#if 0
+ // Apply hex, uppercase, showbase formatting while converting to string
+ std::string si = convert_to<std::string>(extractor<std::string>(
+ (ios.clear(), ios << std::showbase << std::uppercase << std::hex << i, ios)));
+ BOOST_ASSERT(si == "0XFF");
+
+ {
+ std::string double_str = "1.2345e-02";
+ std::stringstream ios;
+ double d = convert_to<double>(extractor<double>(
+ (ios.clear(), ios << double_str, ios >> std::setprecision(4) >> std::scientific)));
+
+ std::string sd= convert_to<std::string>(extractor<std::string>(
+ (ios.clear(), ios << std::setprecision(4) << std::scientific << d, ios)));
+
+ BOOST_ASSERT(sd == double_str);
+ }
+#endif
+ return 0;
+ }
+
+//]
Modified: sandbox/conversion/libs/conversion_ext/example/no_throw.cpp
==============================================================================
--- sandbox/conversion/libs/conversion_ext/example/no_throw.cpp (original)
+++ sandbox/conversion/libs/conversion_ext/example/no_throw.cpp 2011-06-26 15:49:25 EDT (Sun, 26 Jun 2011)
@@ -32,7 +32,6 @@
void try_convert_to_way()
{
std::string str="not an int";
- int t;
//[NO_THROW_CPP_TRY_CONVERT_WAY
optional<int> optt = try_convert_to<int>(str);
if (!optt)
@@ -45,7 +44,6 @@
void convert_to_optional_way()
{
std::string str="not an int";
- int t;
//[NO_THROW_CPP_TRY_CONVERT_TO_OPT_WAY
optional<int> optt = convert_to<optional<int> >(str);
if (!optt)
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