Index: boost/tuple/tuple_io.hpp =================================================================== --- boost/tuple/tuple_io.hpp (revision 51856) +++ boost/tuple/tuple_io.hpp (working copy) @@ -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 inline std::ostream& operator<<(std::ostream& o, const cons& t) { if (!o.good() ) return o; @@ -305,6 +320,23 @@ #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, Index: libs/tuple/test/io_test.cpp =================================================================== --- libs/tuple/test/io_test.cpp (revision 51856) +++ libs/tuple/test/io_test.cpp (working copy) @@ -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,13 +107,20 @@ // reading tuple in format (a b c); - useThisIStringStream is("(100 200 300)"); + useThisIStringStream is1("(100 200 300)"); - tuple ti; - BOOST_CHECK(bool(is >> ti)); - BOOST_CHECK(ti == make_tuple(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 // general. If this is wanted, some kind of a parseable string class