123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #ifndef BOOST_PFR_IO_HPP
- #define BOOST_PFR_IO_HPP
- #pragma once
- #include <boost/pfr/detail/config.hpp>
- #include <boost/pfr/detail/detectors.hpp>
- #include <boost/pfr/io_fields.hpp>
- namespace boost { namespace pfr {
- namespace detail {
- template <class Stream, class Type>
- using enable_not_ostreamable_t = std::enable_if_t<
- not_appliable<ostreamable_detector, Stream&, const std::remove_reference_t<Type>&>::value,
- Stream&
- >;
- template <class Stream, class Type>
- using enable_not_istreamable_t = std::enable_if_t<
- not_appliable<istreamable_detector, Stream&, Type&>::value,
- Stream&
- >;
- template <class Stream, class Type>
- using enable_ostreamable_t = std::enable_if_t<
- !not_appliable<ostreamable_detector, Stream&, const std::remove_reference_t<Type>&>::value,
- Stream&
- >;
- template <class Stream, class Type>
- using enable_istreamable_t = std::enable_if_t<
- !not_appliable<istreamable_detector, Stream&, Type&>::value,
- Stream&
- >;
- template <class T>
- struct io_impl {
- T value;
- };
- template <class Char, class Traits, class T>
- enable_not_ostreamable_t<std::basic_ostream<Char, Traits>, T> operator<<(std::basic_ostream<Char, Traits>& out, io_impl<T>&& x) {
- return out << boost::pfr::io_fields(std::forward<T>(x.value));
- }
- template <class Char, class Traits, class T>
- enable_ostreamable_t<std::basic_ostream<Char, Traits>, T> operator<<(std::basic_ostream<Char, Traits>& out, io_impl<T>&& x) {
- return out << x.value;
- }
- template <class Char, class Traits, class T>
- enable_not_istreamable_t<std::basic_istream<Char, Traits>, T> operator>>(std::basic_istream<Char, Traits>& in, io_impl<T>&& x) {
- return in >> boost::pfr::io_fields(std::forward<T>(x.value));
- }
- template <class Char, class Traits, class T>
- enable_istreamable_t<std::basic_istream<Char, Traits>, T> operator>>(std::basic_istream<Char, Traits>& in, io_impl<T>&& x) {
- return in >> x.value;
- }
- }
- template <class T>
- auto io(T&& value) noexcept {
- return detail::io_impl<T>{std::forward<T>(value)};
- }
- }}
- #endif
|