forked from boostorg/variant2
Add operator<< for monostate
This commit is contained in:
@ -2263,6 +2263,13 @@ template<class Os, class T> struct is_output_streamable<Os, T, decltype( std::de
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class Ch, class Tr>
|
||||
std::basic_ostream<Ch, Tr>& operator<<( std::basic_ostream<Ch, Tr>& os, monostate const& )
|
||||
{
|
||||
os << "monostate";
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class Ch, class Tr, class T1, class... T,
|
||||
class E = typename std::enable_if< mp11::mp_all< detail::is_output_streamable<std::basic_ostream<Ch, Tr>, T>... >::value >::type >
|
||||
std::basic_ostream<Ch, Tr>& operator<<( std::basic_ostream<Ch, Tr>& os, variant<T1, T...> const& v )
|
||||
|
@ -30,9 +30,12 @@ int main()
|
||||
BOOST_TEST_TRAIT_FALSE((boost::variant2::detail::is_output_streamable<std::ostream, X>));
|
||||
BOOST_TEST_TRAIT_TRUE((boost::variant2::detail::is_output_streamable<std::ostream, Y>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((boost::variant2::detail::is_output_streamable<std::ostream, boost::variant2::monostate>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((boost::variant2::detail::is_output_streamable<std::ostream, boost::variant2::variant<int, float, std::string>>));
|
||||
BOOST_TEST_TRAIT_FALSE((boost::variant2::detail::is_output_streamable<std::ostream, boost::variant2::variant<int, float, X>>));
|
||||
BOOST_TEST_TRAIT_TRUE((boost::variant2::detail::is_output_streamable<std::ostream, boost::variant2::variant<int, float, Y>>));
|
||||
BOOST_TEST_TRAIT_TRUE((boost::variant2::detail::is_output_streamable<std::ostream, boost::variant2::variant<boost::variant2::monostate, int, float>>));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -20,17 +20,24 @@ template<class T> std::string to_string( T const& t )
|
||||
|
||||
int main()
|
||||
{
|
||||
variant<int, float, std::string> v( 1 );
|
||||
{
|
||||
BOOST_TEST_EQ( to_string( monostate() ), "monostate" );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( to_string( v ), to_string( 1 ) );
|
||||
{
|
||||
variant<monostate, int, float, std::string> v;
|
||||
|
||||
v = 3.14f;
|
||||
BOOST_TEST_EQ( to_string( v ), to_string( monostate() ) );
|
||||
|
||||
BOOST_TEST_EQ( to_string( v ), to_string( 3.14f ) );
|
||||
v = 1;
|
||||
BOOST_TEST_EQ( to_string( v ), to_string( 1 ) );
|
||||
|
||||
v = "test";
|
||||
v = 3.14f;
|
||||
BOOST_TEST_EQ( to_string( v ), to_string( 3.14f ) );
|
||||
|
||||
BOOST_TEST_EQ( to_string( v ), to_string( "test" ) );
|
||||
v = "test";
|
||||
BOOST_TEST_EQ( to_string( v ), to_string( "test" ) );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
Reference in New Issue
Block a user