Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:43:38

0001 // Copyright (c) 2016-2023 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 #include <iosfwd>       // stream operators
0014 #include <iomanip>
0015 
0016 #if defined(__has_include)
0017 #   if __has_include(<string_view>) && BOOST_PFR_USE_CPP17
0018 #       include <string_view>
0019 #   endif
0020 #endif
0021 
0022 namespace boost { namespace pfr { namespace detail {
0023 
0024 inline auto quoted_helper(const std::string& s) noexcept {
0025     return std::quoted(s);
0026 }
0027 
0028 #if defined(__has_include)
0029 #   if __has_include(<string_view>) && BOOST_PFR_USE_CPP17
0030 template <class CharT, class Traits>
0031 inline auto quoted_helper(std::basic_string_view<CharT, Traits> s) noexcept {
0032     return std::quoted(s);
0033 }
0034 #   endif
0035 #endif
0036 
0037 inline auto quoted_helper(std::string& s) noexcept {
0038     return std::quoted(s);
0039 }
0040 
0041 template <class T>
0042 inline decltype(auto) quoted_helper(T&& v) noexcept {
0043     return std::forward<T>(v);
0044 }
0045 
0046 template <std::size_t I, std::size_t N>
0047 struct print_impl {
0048     template <class Stream, class T>
0049     static void print (Stream& out, const T& value) {
0050         if (!!I) out << ", ";
0051         out << detail::quoted_helper(boost::pfr::detail::sequence_tuple::get<I>(value));
0052         print_impl<I + 1, N>::print(out, value);
0053     }
0054 };
0055 
0056 template <std::size_t I>
0057 struct print_impl<I, I> {
0058     template <class Stream, class T> static void print (Stream&, const T&) noexcept {}
0059 };
0060 
0061 
0062 template <std::size_t I, std::size_t N>
0063 struct read_impl {
0064     template <class Stream, class T>
0065     static void read (Stream& in, const T& value) {
0066         char ignore = {};
0067         if (!!I) {
0068             in >> ignore;
0069             if (ignore != ',') in.setstate(Stream::failbit);
0070             in >> ignore;
0071             if (ignore != ' ')  in.setstate(Stream::failbit);
0072         }
0073         in >> detail::quoted_helper( boost::pfr::detail::sequence_tuple::get<I>(value) );
0074         read_impl<I + 1, N>::read(in, value);
0075     }
0076 };
0077 
0078 template <std::size_t I>
0079 struct read_impl<I, I> {
0080     template <class Stream, class T> static void read (Stream&, const T&) {}
0081 };
0082 
0083 }}} // namespace boost::pfr::detail
0084 
0085 #endif // BOOST_PFR_DETAIL_IO_HPP