2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
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)
8 #ifndef BEAST_DETAIL_STREAM_CONCEPTS_HPP
9 #define BEAST_DETAIL_STREAM_CONCEPTS_HPP
11 #include <beast/core/buffer_concepts.hpp>
12 #include <beast/core/error.hpp>
13 #include <boost/asio/io_service.hpp>
14 #include <type_traits>
20 // Types that meet the requirements,
21 // for use with std::declval only.
24 StreamHandler(StreamHandler const&) = default;
25 void operator()(error_code ec, std::size_t);
27 using ReadHandler = StreamHandler;
28 using WriteHandler = StreamHandler;
31 class has_get_io_service
33 template<class U, class R = typename std::is_same<
34 decltype(std::declval<U>().get_io_service()),
35 boost::asio::io_service&>>
38 static std::false_type check(...);
40 using type = decltype(check<T>(0));
44 class is_AsyncReadStream
46 template<class U, class R = decltype(
47 std::declval<U>().async_read_some(
48 std::declval<MutableBufferSequence>(),
49 std::declval<ReadHandler>()),
53 static std::false_type check(...);
54 using type1 = decltype(check<T>(0));
56 using type = std::integral_constant<bool,
58 has_get_io_service<T>::type::value>;
62 class is_AsyncWriteStream
64 template<class U, class R = decltype(
65 std::declval<U>().async_write_some(
66 std::declval<ConstBufferSequence>(),
67 std::declval<WriteHandler>()),
71 static std::false_type check(...);
72 using type1 = decltype(check<T>(0));
74 using type = std::integral_constant<bool,
76 has_get_io_service<T>::type::value>;
80 class is_SyncReadStream
82 template<class U, class R = std::is_same<decltype(
83 std::declval<U>().read_some(
84 std::declval<MutableBufferSequence>())),
88 static std::false_type check1(...);
89 using type1 = decltype(check1<T>(0));
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>>
97 static std::false_type check2(...);
98 using type2 = decltype(check2<T>(0));
101 using type = std::integral_constant<bool,
102 type1::value && type2::value>;
106 class is_SyncWriteStream
108 template<class U, class R = std::is_same<decltype(
109 std::declval<U>().write_some(
110 std::declval<ConstBufferSequence>())),
112 static R check1(int);
114 static std::false_type check1(...);
115 using type1 = decltype(check1<T>(0));
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);
123 static std::false_type check2(...);
124 using type2 = decltype(check2<T>(0));
127 using type = std::integral_constant<bool,
128 type1::value && type2::value>;