diff --git a/include/boost/tuple/tuple_io.hpp b/include/boost/tuple/tuple_io.hpp index b355e56..10cdb1c 100644 --- a/include/boost/tuple/tuple_io.hpp +++ b/include/boost/tuple/tuple_io.hpp @@ -285,6 +285,21 @@ print(std::basic_ostream& o, const cons& t) { } // 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 inline std::ostream& operator<<(std::ostream& o, const cons& t) { if (!o.good() ) return o; @@ -305,6 +320,23 @@ inline std::ostream& operator<<(std::ostream& o, const cons& t) { #else +template +inline std::basic_ostream& +operator<<(std::basic_ostream& 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 inline std::basic_ostream& operator<<(std::basic_ostream& o, diff --git a/test/io_test.cpp b/test/io_test.cpp index f65ad42..ea5460f 100644 --- a/test/io_test.cpp +++ b/test/io_test.cpp @@ -70,6 +70,15 @@ int test_main(int argc, char * argv[] ) { 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 @@ int test_main(int argc, char * argv[] ) { // reading tuple in format (a b c); - useThisIStringStream is("(100 200 300)"); - - tuple ti; - BOOST_CHECK(bool(is >> ti)); - BOOST_CHECK(ti == make_tuple(100, 200, 300)); + useThisIStringStream is1("(100 200 300)"); + tuple 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