File indexing completed on 2025-01-30 09:50:08
0001
0002
0003
0004
0005
0006 #ifndef BOOST_PFR_IO_HPP
0007 #define BOOST_PFR_IO_HPP
0008 #pragma once
0009
0010 #include <boost/pfr/detail/config.hpp>
0011
0012 #include <boost/pfr/detail/detectors.hpp>
0013 #include <boost/pfr/io_fields.hpp>
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 namespace boost { namespace pfr {
0035
0036 namespace detail {
0037
0038
0039 template <class Stream, class Type>
0040 using enable_not_ostreamable_t = std::enable_if_t<
0041 not_appliable<ostreamable_detector, Stream&, const std::remove_reference_t<Type>&>::value,
0042 Stream&
0043 >;
0044
0045 template <class Stream, class Type>
0046 using enable_not_istreamable_t = std::enable_if_t<
0047 not_appliable<istreamable_detector, Stream&, Type&>::value,
0048 Stream&
0049 >;
0050
0051 template <class Stream, class Type>
0052 using enable_ostreamable_t = std::enable_if_t<
0053 !not_appliable<ostreamable_detector, Stream&, const std::remove_reference_t<Type>&>::value,
0054 Stream&
0055 >;
0056
0057 template <class Stream, class Type>
0058 using enable_istreamable_t = std::enable_if_t<
0059 !not_appliable<istreamable_detector, Stream&, Type&>::value,
0060 Stream&
0061 >;
0062
0063
0064
0065 template <class T>
0066 struct io_impl {
0067 T value;
0068 };
0069
0070 template <class Char, class Traits, class T>
0071 enable_not_ostreamable_t<std::basic_ostream<Char, Traits>, T> operator<<(std::basic_ostream<Char, Traits>& out, io_impl<T>&& x) {
0072 return out << boost::pfr::io_fields(std::forward<T>(x.value));
0073 }
0074
0075 template <class Char, class Traits, class T>
0076 enable_ostreamable_t<std::basic_ostream<Char, Traits>, T> operator<<(std::basic_ostream<Char, Traits>& out, io_impl<T>&& x) {
0077 return out << x.value;
0078 }
0079
0080 template <class Char, class Traits, class T>
0081 enable_not_istreamable_t<std::basic_istream<Char, Traits>, T> operator>>(std::basic_istream<Char, Traits>& in, io_impl<T>&& x) {
0082 return in >> boost::pfr::io_fields(std::forward<T>(x.value));
0083 }
0084
0085 template <class Char, class Traits, class T>
0086 enable_istreamable_t<std::basic_istream<Char, Traits>, T> operator>>(std::basic_istream<Char, Traits>& in, io_impl<T>&& x) {
0087 return in >> x.value;
0088 }
0089
0090 }
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106 template <class T>
0107 auto io(T&& value) noexcept {
0108 return detail::io_impl<T>{std::forward<T>(value)};
0109 }
0110
0111 }}
0112
0113 #endif