diff --git a/include/boost/system/result.hpp b/include/boost/system/result.hpp index dca8bda..c30e1c7 100644 --- a/include/boost/system/result.hpp +++ b/include/boost/system/result.hpp @@ -487,6 +487,20 @@ public: } }; +template std::basic_ostream& operator<<( std::basic_ostream& os, result const & r ) +{ + if( r.has_value() ) + { + os << "value:void"; + } + else + { + os << "error:" << r.error(); + } + + return os; +} + } // namespace system } // namespace boost diff --git a/test/result_copy_construct.cpp b/test/result_copy_construct.cpp index 476b020..859a69d 100644 --- a/test/result_copy_construct.cpp +++ b/test/result_copy_construct.cpp @@ -145,5 +145,37 @@ int main() BOOST_TEST_EQ( X::instances, 0 ); + { + result r; + result r2( r ); + + BOOST_TEST_EQ( r, r2 ); + } + + { + result const r; + result r2( r ); + + BOOST_TEST_EQ( r, r2 ); + } + + { + auto ec = make_error_code( errc::invalid_argument ); + + result r( ec ); + result r2( r ); + + BOOST_TEST_EQ( r, r2 ); + } + + { + auto ec = make_error_code( errc::invalid_argument ); + + result const r( ec ); + result r2( r ); + + BOOST_TEST_EQ( r, r2 ); + } + return boost::report_errors(); }