Sprout/sprout/variant/io.hpp

48 lines
1.5 KiB
C++
Raw Normal View History

2013-08-08 09:54:33 +00:00
/*=============================================================================
2015-01-10 10:13:57 +00:00
Copyright (c) 2011-2015 Bolero MURAKAMI
2013-08-08 09:54:33 +00:00
https://github.com/bolero-MURAKAMI/Sprout
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
2012-10-24 11:52:09 +00:00
#ifndef SPROUT_VARIANT_IO_HPP
#define SPROUT_VARIANT_IO_HPP
#include <sprout/config.hpp>
#include <sprout/variant/variant.hpp>
#include <sprout/variant/static_visitor.hpp>
namespace sprout {
namespace detail {
template<typename OStream>
class variant_output_visitor
: public sprout::static_visitor<>
{
public:
typedef OStream ostream_type;
private:
ostream_type& out_;
public:
explicit variant_output_visitor(ostream_type& out)
: out_(out)
{}
template<typename T>
2013-11-02 09:28:18 +00:00
SPROUT_CXX14_CONSTEXPR void operator()(T const& operand) const {
2012-10-24 11:52:09 +00:00
out_ << operand;
}
};
} // namespace detail
//
// operator<<
//
template<typename Elem, typename Traits, typename... Types>
2013-11-02 09:28:18 +00:00
inline SPROUT_NON_CONSTEXPR std::basic_ostream<Elem, Traits>&
2012-10-24 11:52:09 +00:00
operator<<(std::basic_ostream<Elem, Traits>& lhs, sprout::variant<Types...> const& rhs) {
2012-10-28 07:18:40 +00:00
sprout::detail::variant_output_visitor<std::basic_ostream<Elem, Traits> > visitor(lhs);
2012-10-24 11:52:09 +00:00
rhs.apply_visitor(visitor);
2012-10-28 07:18:40 +00:00
return lhs;
2012-10-24 11:52:09 +00:00
}
} // namespace sprout
#endif // #ifndef SPROUT_VARIANT_IO_HPP