diff --git a/include/boost/optional/optional_io.hpp b/include/boost/optional/optional_io.hpp index e7d1a4c..f0ad8ab 100644 --- a/include/boost/optional/optional_io.hpp +++ b/include/boost/optional/optional_io.hpp @@ -28,8 +28,12 @@ inline std::basic_ostream& operator<<(std::basic_ostream& out, none_t const&) { + if (out.good()) + { out << "--"; - return out; + } + + return out; } template @@ -37,9 +41,9 @@ inline std::basic_ostream& operator<<(std::basic_ostream& out, optional const& v) { - if ( out.good() ) + if (out.good()) { - if ( !v ) + if (!v) out << "--" ; else out << ' ' << *v ; } diff --git a/test/optional_test_io.cpp b/test/optional_test_io.cpp index 3ed0511..a4877d5 100644 --- a/test/optional_test_io.cpp +++ b/test/optional_test_io.cpp @@ -61,8 +61,8 @@ void test2( Opt o, Opt buff ) s << o << " " << markv ; s >> buff >> mark ; - BOOST_ASSERT( buff == o ) ; - BOOST_ASSERT( mark == markv ) ; + BOOST_CHECK( buff == o ) ; + BOOST_CHECK( mark == markv ) ; } @@ -75,12 +75,32 @@ void test( T v, T w ) test2( optional () , make_optional(w)); } -void -test() + +template +void subtest_tag_none_reversibility_with_optional(optional ov) { - stringstream s ; - s << boost::none; - BOOST_ASSERT(s.str() == "--"); + stringstream s; + s << boost::none; + s >> ov; + BOOST_CHECK(!ov); +} + +template +void subtest_tag_none_equivalence_with_optional() +{ + stringstream s, r; + optional ov; + s << boost::none; + r << ov; + BOOST_CHECK(s.str() == r.str()); +} + +template +void test_tag_none(T v) +{ + subtest_tag_none_reversibility_with_optional(optional(v)); + subtest_tag_none_reversibility_with_optional(optional()); + subtest_tag_none_equivalence_with_optional(); } @@ -90,7 +110,8 @@ int test_main( int, char* [] ) { test(1,2); test(string("hello"),string("buffer")); - test(); + test_tag_none(10); + test_tag_none(string("text")); } catch ( ... ) {