Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:41:00

0001 // Copyright (c) 2016-2025 Antony Polukhin
0002 //
0003 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #ifndef BOOST_PFR_DETAIL_IO_HPP
0007 #define BOOST_PFR_DETAIL_IO_HPP
0008 #pragma once
0009 
0010 #include <boost/pfr/detail/config.hpp>
0011 
0012 #include <boost/pfr/detail/sequence_tuple.hpp>
0013 
0014 #ifdef BOOST_PFR_HAS_STD_MODULE
0015 import std;
0016 #else
0017 #include <iosfwd>       // stream operators
0018 #include <iomanip>
0019 
0020 #if defined(__has_include)
0021 #   if __has_include(<string_view>) && BOOST_PFR_USE_CPP17
0022 #       include <string_view>
0023 #   endif
0024 #endif
0025 
0026 #endif
0027 
0028 namespace boost { namespace pfr { namespace detail {
0029 
0030 inline auto quoted_helper(const std::string& s) noexcept {
0031     return std::quoted(s);
0032 }
0033 
0034 #if defined(__has_include)
0035 #   if __has_include(<string_view>) && BOOST_PFR_USE_CPP17
0036 template <class CharT, class Traits>
0037 inline auto quoted_helper(std::basic_string_view<CharT, Traits> s) noexcept {
0038     return std::quoted(s);
0039 }
0040 #   endif
0041 #endif
0042 
0043 inline auto quoted_helper(std::string& s) noexcept {
0044     return std::quoted(s);
0045 }
0046 
0047 template <class T>
0048 inline decltype(auto) quoted_helper(T&& v) noexcept {
0049     return std::forward<T>(v);
0050 }
0051 
0052 template <std::size_t I, std::size_t N>
0053 struct print_impl {
0054     template <class Stream, class T>
0055     static void print (Stream& out, const T& value) {
0056         if (!!I) out << ", ";
0057         out << detail::quoted_helper(boost::pfr::detail::sequence_tuple::get<I>(value));
0058         print_impl<I + 1, N>::print(out, value);
0059     }
0060 };
0061 
0062 template <std::size_t I>
0063 struct print_impl<I, I> {
0064     template <class Stream, class T> static void print (Stream&, const T&) noexcept {}
0065 };
0066 
0067 
0068 template <std::size_t I, std::size_t N>
0069 struct read_impl {
0070     template <class Stream, class T>
0071     static void read (Stream& in, const T& value) {
0072         char ignore = {};
0073         if (!!I) {
0074             in >> ignore;
0075             if (ignore != ',') in.setstate(Stream::failbit);
0076             in >> ignore;
0077             if (ignore != ' ')  in.setstate(Stream::failbit);
0078         }
0079         in >> detail::quoted_helper( boost::pfr::detail::sequence_tuple::get<I>(value) );
0080         read_impl<I + 1, N>::read(in, value);
0081     }
0082 };
0083 
0084 template <std::size_t I>
0085 struct read_impl<I, I> {
0086     template <class Stream, class T> static void read (Stream&, const T&) {}
0087 };
0088 
0089 }}} // namespace boost::pfr::detail
0090 
0091 #endif // BOOST_PFR_DETAIL_IO_HPP