File indexing completed on 2025-12-16 09:59:58
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 BOOST_PFR_BEGIN_MODULE_EXPORT
0071
0072 template <class Char, class Traits, class T>
0073 enable_not_ostreamable_t<std::basic_ostream<Char, Traits>, T> operator<<(std::basic_ostream<Char, Traits>& out, io_impl<T>&& x) {
0074 return out << boost::pfr::io_fields(std::forward<T>(x.value));
0075 }
0076
0077 template <class Char, class Traits, class T>
0078 enable_ostreamable_t<std::basic_ostream<Char, Traits>, T> operator<<(std::basic_ostream<Char, Traits>& out, io_impl<T>&& x) {
0079 return out << x.value;
0080 }
0081
0082 template <class Char, class Traits, class T>
0083 enable_not_istreamable_t<std::basic_istream<Char, Traits>, T> operator>>(std::basic_istream<Char, Traits>& in, io_impl<T>&& x) {
0084 return in >> boost::pfr::io_fields(std::forward<T>(x.value));
0085 }
0086
0087 template <class Char, class Traits, class T>
0088 enable_istreamable_t<std::basic_istream<Char, Traits>, T> operator>>(std::basic_istream<Char, Traits>& in, io_impl<T>&& x) {
0089 return in >> x.value;
0090 }
0091
0092 BOOST_PFR_END_MODULE_EXPORT
0093
0094 }
0095
0096 BOOST_PFR_BEGIN_MODULE_EXPORT
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112 template <class T>
0113 auto io(T&& value) noexcept {
0114 return detail::io_impl<T>{std::forward<T>(value)};
0115 }
0116
0117 BOOST_PFR_END_MODULE_EXPORT
0118
0119 }}
0120
0121 #endif