From 1d3446304bce7ab730448a3b2fdb78945e06f422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Hunold?= Date: Mon, 24 Nov 2014 15:38:24 +0100 Subject: [PATCH] Add operator<< for boost::none --- include/boost/optional/optional_io.hpp | 9 +++++++++ test/optional_test_io.cpp | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/boost/optional/optional_io.hpp b/include/boost/optional/optional_io.hpp index 4c1c610..e7d1a4c 100644 --- a/include/boost/optional/optional_io.hpp +++ b/include/boost/optional/optional_io.hpp @@ -23,6 +23,15 @@ namespace boost { +template +inline +std::basic_ostream& +operator<<(std::basic_ostream& out, none_t const&) +{ + out << "--"; + return out; +} + template inline std::basic_ostream& diff --git a/test/optional_test_io.cpp b/test/optional_test_io.cpp index d4ee207..3ed0511 100644 --- a/test/optional_test_io.cpp +++ b/test/optional_test_io.cpp @@ -75,12 +75,22 @@ void test( T v, T w ) test2( optional () , make_optional(w)); } +void +test() +{ + stringstream s ; + s << boost::none; + BOOST_ASSERT(s.str() == "--"); +} + + int test_main( int, char* [] ) { try { test(1,2); test(string("hello"),string("buffer")); + test(); } catch ( ... ) {