Blame view

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