forked from boostorg/variant2
Add operator<< for variant
This commit is contained in:
@ -25,6 +25,7 @@
|
||||
#include <utility>
|
||||
#include <functional> // std::hash
|
||||
#include <cstdint>
|
||||
#include <iosfwd>
|
||||
|
||||
//
|
||||
|
||||
@ -2236,6 +2237,30 @@ template<class R = detail::deduced, class V, class... F> constexpr auto visit_by
|
||||
detail::visit_by_index_L<R, V, F...>{ std::forward<V>(v), std::tuple<F&&...>( std::forward<F>(f)... ) } );
|
||||
}
|
||||
|
||||
// output streaming
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class Ch, class Tr, class... T> struct ostream_insert_L
|
||||
{
|
||||
std::basic_ostream<Ch, Tr>& os;
|
||||
variant<T...> const& v;
|
||||
|
||||
template<class I> std::basic_ostream<Ch, Tr>& operator()( I ) const
|
||||
{
|
||||
return os << unsafe_get<I::value>( v );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class Ch, class Tr, class... T> std::basic_ostream<Ch, Tr>& operator<<( std::basic_ostream<Ch, Tr>& os, variant<T...> const& v )
|
||||
{
|
||||
return mp11::mp_with_index<sizeof...(T)>( v.index(),
|
||||
detail::ostream_insert_L<Ch, Tr, T...>{ os, v } );
|
||||
}
|
||||
|
||||
// hashing support
|
||||
|
||||
namespace detail
|
||||
|
Reference in New Issue
Block a user