Improvement to "cout << none" implementation

This commit is contained in:
Andrzej Krzemienski
2014-11-24 22:53:59 +01:00
parent f8bbb9fabb
commit 0d06d66f5c
2 changed files with 36 additions and 11 deletions

View File

@ -27,8 +27,12 @@ template<class CharType, class CharTrait>
inline
std::basic_ostream<CharType, CharTrait>&
operator<<(std::basic_ostream<CharType, CharTrait>& out, none_t const&)
{
if (out.good())
{
out << "--";
}
return out;
}

View File

@ -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<T> () , make_optional(w));
}
void
test()
template <class T>
void subtest_tag_none_reversibility_with_optional(optional<T> ov)
{
stringstream s;
s << boost::none;
BOOST_ASSERT(s.str() == "--");
s >> ov;
BOOST_CHECK(!ov);
}
template <class T>
void subtest_tag_none_equivalence_with_optional()
{
stringstream s, r;
optional<T> ov;
s << boost::none;
r << ov;
BOOST_CHECK(s.str() == r.str());
}
template <class T>
void test_tag_none(T v)
{
subtest_tag_none_reversibility_with_optional(optional<T>(v));
subtest_tag_none_reversibility_with_optional(optional<T>());
subtest_tag_none_equivalence_with_optional<T>();
}
@ -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 ( ... )
{