ゴミ箱
type_traits.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/boostorg/beast
8 //
9 
10 #ifndef BOOST_BEAST_HTTP_DETAIL_TYPE_TRAITS_HPP
11 #define BOOST_BEAST_HTTP_DETAIL_TYPE_TRAITS_HPP
12 
14 #include <boost/optional.hpp>
15 #include <cstdint>
16 
17 namespace boost {
18 namespace beast {
19 namespace http {
20 
21 template<bool isRequest, class Fields>
22 struct header;
23 
24 template<bool, class, class>
25 struct message;
26 
27 template<bool isRequest,class Body, class Fields>
28 class parser;
29 
30 namespace detail {
31 
32 template<class T>
34 {
35  template<bool b, class F>
36  static std::true_type check(
37  header<b, F> const*);
38  static std::false_type check(...);
39 public:
40  using type = decltype(check((T*)0));
41 };
42 
43 template<class T>
45 
46 template<class T>
47 struct is_parser : std::false_type {};
48 
49 template<bool isRequest, class Body, class Fields>
50 struct is_parser<parser<isRequest, Body, Fields>> : std::true_type {};
51 
53 {
54  string_view method() const;
55  string_view reason() const;
56  string_view target() const;
57 
58 protected:
59  string_view get_method_impl() const;
60  string_view get_target_impl() const;
61  string_view get_reason_impl() const;
62  bool get_chunked_impl() const;
63  bool get_keep_alive_impl(unsigned) const;
64  void set_method_impl(string_view);
65  void set_target_impl(string_view);
66  void set_reason_impl(string_view);
67  void set_chunked_impl(bool);
68  void set_content_length_impl(boost::optional<std::uint64_t>);
69  void set_keep_alive_impl(unsigned, bool);
70 };
71 
72 template<class T, class = beast::detail::void_t<>>
73 struct has_value_type : std::false_type {};
74 
75 template<class T>
76 struct has_value_type<T, beast::detail::void_t<
77  typename T::value_type
78  > > : std::true_type {};
79 
85 template<class T, class = void>
86 struct is_body_sized : std::false_type {};
87 
88 template<class T>
89 struct is_body_sized<T, beast::detail::void_t<
90  typename T::value_type,
91  decltype(
92  std::declval<std::uint64_t&>() =
93  T::size(std::declval<typename T::value_type const&>()),
94  (void)0)>> : std::true_type {};
95 
96 template<class T>
97 struct is_fields_helper : T
98 {
99  template<class U = is_fields_helper>
100  static auto f1(int) -> decltype(
101  std::declval<string_view&>() = std::declval<U const&>().get_method_impl(),
102  std::true_type());
103  static auto f1(...) -> std::false_type;
104  using t1 = decltype(f1(0));
105 
106  template<class U = is_fields_helper>
107  static auto f2(int) -> decltype(
108  std::declval<string_view&>() = std::declval<U const&>().get_target_impl(),
109  std::true_type());
110  static auto f2(...) -> std::false_type;
111  using t2 = decltype(f2(0));
112 
113  template<class U = is_fields_helper>
114  static auto f3(int) -> decltype(
115  std::declval<string_view&>() = std::declval<U const&>().get_reason_impl(),
116  std::true_type());
117  static auto f3(...) -> std::false_type;
118  using t3 = decltype(f3(0));
119 
120  template<class U = is_fields_helper>
121  static auto f4(int) -> decltype(
122  std::declval<bool&>() = std::declval<U const&>().get_chunked_impl(),
123  std::true_type());
124  static auto f4(...) -> std::false_type;
125  using t4 = decltype(f4(0));
126 
127  template<class U = is_fields_helper>
128  static auto f5(int) -> decltype(
129  std::declval<bool&>() = std::declval<U const&>().get_keep_alive_impl(
130  std::declval<unsigned>()),
131  std::true_type());
132  static auto f5(...) -> std::false_type;
133  using t5 = decltype(f5(0));
134 
135  template<class U = is_fields_helper>
136  static auto f6(int) -> decltype(
137  void(std::declval<U&>().set_method_impl(std::declval<string_view>())),
138  std::true_type());
139  static auto f6(...) -> std::false_type;
140  using t6 = decltype(f6(0));
141 
142  template<class U = is_fields_helper>
143  static auto f7(int) -> decltype(
144  void(std::declval<U&>().set_target_impl(std::declval<string_view>())),
145  std::true_type());
146  static auto f7(...) -> std::false_type;
147  using t7 = decltype(f7(0));
148 
149  template<class U = is_fields_helper>
150  static auto f8(int) -> decltype(
151  void(std::declval<U&>().set_reason_impl(std::declval<string_view>())),
152  std::true_type());
153  static auto f8(...) -> std::false_type;
154  using t8 = decltype(f8(0));
155 
156  template<class U = is_fields_helper>
157  static auto f9(int) -> decltype(
158  void(std::declval<U&>().set_chunked_impl(std::declval<bool>())),
159  std::true_type());
160  static auto f9(...) -> std::false_type;
161  using t9 = decltype(f9(0));
162 
163  template<class U = is_fields_helper>
164  static auto f10(int) -> decltype(
165  void(std::declval<U&>().set_content_length_impl(
166  std::declval<boost::optional<std::uint64_t>>())),
167  std::true_type());
168  static auto f10(...) -> std::false_type;
169  using t10 = decltype(f10(0));
170 
171  template<class U = is_fields_helper>
172  static auto f11(int) -> decltype(
173  void(std::declval<U&>().set_keep_alive_impl(
174  std::declval<unsigned>(),
175  std::declval<bool>())),
176  std::true_type());
177  static auto f11(...) -> std::false_type;
178  using t11 = decltype(f11(0));
179 
180  using type = std::integral_constant<bool,
181  t1::value && t2::value && t3::value &&
182  t4::value && t5::value && t6::value &&
183  t7::value && t8::value && t9::value &&
184  t10::value && t11::value>;
185 };
186 
187 } // detail
188 } // http
189 } // beast
190 } // boost
191 
192 #endif
Definition: async_result.hpp:20
Definition: type_traits.hpp:86
Definition: type_traits.hpp:25
decltype(f5(0)) t5
Definition: type_traits.hpp:133
decltype(f10(0)) t10
Definition: type_traits.hpp:169
Definition: beast_common.hpp:6
std::integral_constant< bool, t1::value &&t2::value &&t3::value &&t4::value &&t5::value &&t6::value &&t7::value &&t8::value &&t9::value &&t10::value &&t11::value > type
Definition: type_traits.hpp:184
decltype(check((T *) 0)) type
Definition: type_traits.hpp:40
Definition: type_traits.hpp:47
decltype(f9(0)) t9
Definition: type_traits.hpp:161
decltype(f11(0)) t11
Definition: type_traits.hpp:178
Definition: type_traits.hpp:33
typename is_header_impl< T >::type is_header
Definition: type_traits.hpp:44
typename make_void< Ts... >::type void_t
Definition: type_traits.hpp:62
Definition: type_traits.hpp:97
Definition: type_traits.hpp:28
decltype(f3(0)) t3
Definition: type_traits.hpp:118
Definition: type_traits.hpp:73
boost::string_ref string_view
The type of string view used by the library.
Definition: string.hpp:36
decltype(f2(0)) t2
Definition: type_traits.hpp:111
decltype(f7(0)) t7
Definition: type_traits.hpp:147
decltype(f6(0)) t6
Definition: type_traits.hpp:140
Definition: type_traits.hpp:22
decltype(f4(0)) t4
Definition: type_traits.hpp:125
Definition: type_traits.hpp:52
decltype(f8(0)) t8
Definition: type_traits.hpp:154
decltype(f1(0)) t1
Definition: type_traits.hpp:104