Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53211 - in trunk: boost/tuple libs/tuple/test
From: steven_at_[hidden]
Date: 2009-05-23 12:39:14


Author: steven_watanabe
Date: 2009-05-23 12:39:13 EDT (Sat, 23 May 2009)
New Revision: 53211
URL: http://svn.boost.org/trac/boost/changeset/53211

Log:
Allow printing an empty tuple
Text files modified:
   trunk/boost/tuple/tuple_io.hpp | 32 ++++++++++++++++++++++++++++++++
   trunk/libs/tuple/test/io_test.cpp | 26 +++++++++++++++++++++-----
   2 files changed, 53 insertions(+), 5 deletions(-)

Modified: trunk/boost/tuple/tuple_io.hpp
==============================================================================
--- trunk/boost/tuple/tuple_io.hpp (original)
+++ trunk/boost/tuple/tuple_io.hpp 2009-05-23 12:39:13 EDT (Sat, 23 May 2009)
@@ -285,6 +285,21 @@
 } // namespace detail
 
 #if defined (BOOST_NO_TEMPLATED_STREAMS)
+
+inline std::ostream& operator<<(std::ostream& o, const null_type& t) {
+ if (!o.good() ) return o;
+
+ const char l =
+ detail::format_info::get_manipulator(o, detail::format_info::open);
+ const char r =
+ detail::format_info::get_manipulator(o, detail::format_info::close);
+
+ o << l;
+ o << r;
+
+ return o;
+}
+
 template<class T1, class T2>
 inline std::ostream& operator<<(std::ostream& o, const cons<T1, T2>& t) {
   if (!o.good() ) return o;
@@ -305,6 +320,23 @@
 
 #else
 
+template<class CharType, class CharTrait>
+inline std::basic_ostream<CharType, CharTrait>&
+operator<<(std::basic_ostream<CharType, CharTrait>& o,
+ const null_type& t) {
+ if (!o.good() ) return o;
+
+ const CharType l =
+ detail::format_info::get_manipulator(o, detail::format_info::open);
+ const CharType r =
+ detail::format_info::get_manipulator(o, detail::format_info::close);
+
+ o << l;
+ o << r;
+
+ return o;
+}
+
 template<class CharType, class CharTrait, class T1, class T2>
 inline std::basic_ostream<CharType, CharTrait>&
 operator<<(std::basic_ostream<CharType, CharTrait>& o,

Modified: trunk/libs/tuple/test/io_test.cpp
==============================================================================
--- trunk/libs/tuple/test/io_test.cpp (original)
+++ trunk/libs/tuple/test/io_test.cpp 2009-05-23 12:39:13 EDT (Sat, 23 May 2009)
@@ -70,6 +70,15 @@
   os1 << make_tuple(1, 2, 3);
   BOOST_CHECK (os1.str() == std::string("[1,2,3][1,2,3]") );
 
+ // check empty tuple.
+ useThisOStringStream os3;
+ os3 << make_tuple();
+ BOOST_CHECK (os3.str() == std::string("()") );
+ os3 << set_open('[');
+ os3 << set_close(']');
+ os3 << make_tuple();
+ BOOST_CHECK (os3.str() == std::string("()[]") );
+
   ofstream tmp("temp.tmp");
 
 #if !defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
@@ -98,12 +107,19 @@
 
 
   // reading tuple<int, int, int> in format (a b c);
- useThisIStringStream is("(100 200 300)");
-
- tuple<int, int, int> ti;
- BOOST_CHECK(bool(is >> ti));
- BOOST_CHECK(ti == make_tuple(100, 200, 300));
+ useThisIStringStream is1("(100 200 300)");
    
+ tuple<int, int, int> ti1;
+ BOOST_CHECK(bool(is1 >> ti1));
+ BOOST_CHECK(ti1 == make_tuple(100, 200, 300));
+
+ useThisIStringStream is2("()");
+ tuple<> ti2;
+ BOOST_CHECK(bool(is2 >> ti2));
+ useThisIStringStream is3("[]");
+ is3 >> set_open('[');
+ is3 >> set_close(']');
+ BOOST_CHECK(bool(is3 >> ti2));
 
   // Note that strings are problematic:
   // writing a tuple on a stream and reading it back doesn't work in


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