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_BUFFER_CONCEPTS_HPP
9 #define BEAST_DETAIL_BUFFER_CONCEPTS_HPP
11 #include <boost/asio/buffer.hpp>
13 #include <type_traits>
18 // Types that meet the requirements,
19 // for use with std::declval only.
20 template<class BufferType>
23 using value_type = BufferType;
24 using const_iterator = BufferType const*;
26 BufferSequence(BufferSequence const&) = default;
27 const_iterator begin() const noexcept;
28 const_iterator end() const noexcept;
30 using ConstBufferSequence =
31 BufferSequence<boost::asio::const_buffer>;
32 using MutableBufferSequence =
33 BufferSequence<boost::asio::mutable_buffer>;
35 template<class T, class BufferType>
36 class is_BufferSequence
38 template<class U, class R = std::is_convertible<
39 typename U::value_type, BufferType> >
42 static std::false_type check1(...);
43 using type1 = decltype(check1<T>(0));
45 template<class U, class R = std::is_base_of<
47 std::bidirectional_iterator_tag,
48 typename std::iterator_traits<
49 typename U::const_iterator>::iterator_category>>
52 // boost::asio::detail::consuming_buffers::const_iterator
53 // is not bidirectional
54 std::forward_iterator_tag,
55 typename std::iterator_traits<
56 typename U::const_iterator>::iterator_category>>
60 static std::false_type check2(...);
61 using type2 = decltype(check2<T>(0));
63 template<class U, class R = typename
64 std::is_convertible<decltype(
65 std::declval<U>().begin()),
66 typename U::const_iterator>::type>
69 static std::false_type check3(...);
70 using type3 = decltype(check3<T>(0));
72 template<class U, class R = typename std::is_convertible<decltype(
73 std::declval<U>().end()),
74 typename U::const_iterator>::type>
77 static std::false_type check4(...);
78 using type4 = decltype(check4<T>(0));
81 using type = std::integral_constant<bool,
82 std::is_copy_constructible<T>::value &&
83 std::is_destructible<T>::value &&
84 type1::value && type2::value &&
85 type3::value && type4::value>;
88 template<class B1, class... Bn>
89 struct is_all_ConstBufferSequence
90 : std::integral_constant<bool,
91 is_BufferSequence<B1, boost::asio::const_buffer>::type::value &&
92 is_all_ConstBufferSequence<Bn...>::value>
97 struct is_all_ConstBufferSequence<B1>
98 : is_BufferSequence<B1, boost::asio::const_buffer>::type
103 class is_DynamicBuffer
106 template<class U, class R = std::is_convertible<decltype(
107 std::declval<U const>().size()), std::size_t>>
108 static R check1(int);
110 static std::false_type check1(...);
111 using type1 = decltype(check1<T>(0));
114 template<class U, class R = std::is_convertible<decltype(
115 std::declval<U const>().max_size()), std::size_t>>
116 static R check2(int);
118 static std::false_type check2(...);
119 using type2 = decltype(check2<T>(0));
122 template<class U, class R = std::is_convertible<decltype(
123 std::declval<U const>().capacity()), std::size_t>>
124 static R check3(int);
126 static std::false_type check3(...);
127 using type3 = decltype(check3<T>(0));
130 template<class U, class R = std::integral_constant<
131 bool, is_BufferSequence<decltype(
132 std::declval<U const>().data()),
133 boost::asio::const_buffer>::type::value>>
134 static R check4(int);
136 static std::false_type check4(...);
137 using type4 = decltype(check4<T>(0));
140 template<class U, class R = std::integral_constant<
141 bool, is_BufferSequence<decltype(
142 std::declval<U>().prepare(1)),
143 boost::asio::mutable_buffer>::type::value>>
144 static R check5(int);
146 static std::false_type check5(...);
147 using type5 = decltype(check5<T>(0));
150 template<class U, class R = decltype(
151 std::declval<U>().commit(1), std::true_type{})>
152 static R check6(int);
154 static std::false_type check6(...);
155 using type6 = decltype(check6<T>(0));
158 template<class U, class R = decltype(
159 std::declval<U>().consume(1), std::true_type{})>
160 static R check7(int);
162 static std::false_type check7(...);
163 using type7 = decltype(check7<T>(0));
166 using type = std::integral_constant<bool,
169 //&& type3::value // Networking TS