]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/pfr/detail/io.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / pfr / detail / io.hpp
1 // Copyright (c) 2016-2022 Antony Polukhin
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #ifndef BOOST_PFR_DETAIL_IO_HPP
7 #define BOOST_PFR_DETAIL_IO_HPP
8 #pragma once
9
10 #include <boost/pfr/detail/config.hpp>
11
12 #include <boost/pfr/detail/sequence_tuple.hpp>
13 #include <iosfwd> // stream operators
14 #include <iomanip>
15
16 #if defined(__has_include)
17 # if __has_include(<string_view>) && BOOST_PFR_USE_CPP17
18 # include <string_view>
19 # endif
20 #endif
21
22 namespace boost { namespace pfr { namespace detail {
23
24 inline auto quoted_helper(const std::string& s) noexcept {
25 return std::quoted(s);
26 }
27
28 #if defined(__has_include)
29 # if __has_include(<string_view>) && BOOST_PFR_USE_CPP17
30 template <class CharT, class Traits>
31 inline auto quoted_helper(std::basic_string_view<CharT, Traits> s) noexcept {
32 return std::quoted(s);
33 }
34 # endif
35 #endif
36
37 inline auto quoted_helper(std::string& s) noexcept {
38 return std::quoted(s);
39 }
40
41 template <class T>
42 inline decltype(auto) quoted_helper(T&& v) noexcept {
43 return std::forward<T>(v);
44 }
45
46 template <std::size_t I, std::size_t N>
47 struct print_impl {
48 template <class Stream, class T>
49 static void print (Stream& out, const T& value) {
50 if (!!I) out << ", ";
51 out << detail::quoted_helper(boost::pfr::detail::sequence_tuple::get<I>(value));
52 print_impl<I + 1, N>::print(out, value);
53 }
54 };
55
56 template <std::size_t I>
57 struct print_impl<I, I> {
58 template <class Stream, class T> static void print (Stream&, const T&) noexcept {}
59 };
60
61
62 template <std::size_t I, std::size_t N>
63 struct read_impl {
64 template <class Stream, class T>
65 static void read (Stream& in, const T& value) {
66 char ignore = {};
67 if (!!I) {
68 in >> ignore;
69 if (ignore != ',') in.setstate(Stream::failbit);
70 in >> ignore;
71 if (ignore != ' ') in.setstate(Stream::failbit);
72 }
73 in >> detail::quoted_helper( boost::pfr::detail::sequence_tuple::get<I>(value) );
74 read_impl<I + 1, N>::read(in, value);
75 }
76 };
77
78 template <std::size_t I>
79 struct read_impl<I, I> {
80 template <class Stream, class T> static void read (Stream&, const T&) {}
81 };
82
83 }}} // namespace boost::pfr::detail
84
85 #endif // BOOST_PFR_DETAIL_IO_HPP