]> git.proxmox.com Git - ceph.git/blob - ceph/src/Beast/include/beast/core/detail/stream_concepts.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / Beast / include / beast / core / detail / stream_concepts.hpp
1 //
2 // Copyright (c) 2013-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
8 #ifndef BEAST_DETAIL_STREAM_CONCEPTS_HPP
9 #define BEAST_DETAIL_STREAM_CONCEPTS_HPP
10
11 #include <beast/core/buffer_concepts.hpp>
12 #include <beast/core/error.hpp>
13 #include <boost/asio/io_service.hpp>
14 #include <type_traits>
15 #include <utility>
16
17 namespace beast {
18 namespace detail {
19
20 // Types that meet the requirements,
21 // for use with std::declval only.
22 struct StreamHandler
23 {
24 StreamHandler(StreamHandler const&) = default;
25 void operator()(error_code ec, std::size_t);
26 };
27 using ReadHandler = StreamHandler;
28 using WriteHandler = StreamHandler;
29
30 template<class T>
31 class has_get_io_service
32 {
33 template<class U, class R = typename std::is_same<
34 decltype(std::declval<U>().get_io_service()),
35 boost::asio::io_service&>>
36 static R check(int);
37 template<class>
38 static std::false_type check(...);
39 public:
40 using type = decltype(check<T>(0));
41 };
42
43 template<class T>
44 class is_AsyncReadStream
45 {
46 template<class U, class R = decltype(
47 std::declval<U>().async_read_some(
48 std::declval<MutableBufferSequence>(),
49 std::declval<ReadHandler>()),
50 std::true_type{})>
51 static R check(int);
52 template<class>
53 static std::false_type check(...);
54 using type1 = decltype(check<T>(0));
55 public:
56 using type = std::integral_constant<bool,
57 type1::value &&
58 has_get_io_service<T>::type::value>;
59 };
60
61 template<class T>
62 class is_AsyncWriteStream
63 {
64 template<class U, class R = decltype(
65 std::declval<U>().async_write_some(
66 std::declval<ConstBufferSequence>(),
67 std::declval<WriteHandler>()),
68 std::true_type{})>
69 static R check(int);
70 template<class>
71 static std::false_type check(...);
72 using type1 = decltype(check<T>(0));
73 public:
74 using type = std::integral_constant<bool,
75 type1::value &&
76 has_get_io_service<T>::type::value>;
77 };
78
79 template<class T>
80 class is_SyncReadStream
81 {
82 template<class U, class R = std::is_same<decltype(
83 std::declval<U>().read_some(
84 std::declval<MutableBufferSequence>())),
85 std::size_t>>
86 static R check1(int);
87 template<class>
88 static std::false_type check1(...);
89 using type1 = decltype(check1<T>(0));
90
91 template<class U, class R = std::is_same<decltype(
92 std::declval<U>().read_some(
93 std::declval<MutableBufferSequence>(),
94 std::declval<error_code&>())), std::size_t>>
95 static R check2(int);
96 template<class>
97 static std::false_type check2(...);
98 using type2 = decltype(check2<T>(0));
99
100 public:
101 using type = std::integral_constant<bool,
102 type1::value && type2::value>;
103 };
104
105 template<class T>
106 class is_SyncWriteStream
107 {
108 template<class U, class R = std::is_same<decltype(
109 std::declval<U>().write_some(
110 std::declval<ConstBufferSequence>())),
111 std::size_t>>
112 static R check1(int);
113 template<class>
114 static std::false_type check1(...);
115 using type1 = decltype(check1<T>(0));
116
117 template<class U, class R = std::is_same<decltype(
118 std::declval<U>().write_some(
119 std::declval<ConstBufferSequence>(),
120 std::declval<error_code&>())), std::size_t>>
121 static R check2(int);
122 template<class>
123 static std::false_type check2(...);
124 using type2 = decltype(check2<T>(0));
125
126 public:
127 using type = std::integral_constant<bool,
128 type1::value && type2::value>;
129 };
130
131 } // detail
132 } // beast
133
134 #endif