is_buffer_sequence.hpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. //
  2. // detail/is_buffer_sequence.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_DETAIL_IS_BUFFER_SEQUENCE_HPP
  11. #define BOOST_ASIO_DETAIL_IS_BUFFER_SEQUENCE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/detail/type_traits.hpp>
  17. #include <boost/asio/detail/push_options.hpp>
  18. namespace boost {
  19. namespace asio {
  20. class mutable_buffer;
  21. class const_buffer;
  22. namespace detail {
  23. struct buffer_sequence_memfns_base
  24. {
  25. void begin();
  26. void end();
  27. void size();
  28. void max_size();
  29. void capacity();
  30. void data();
  31. void prepare();
  32. void commit();
  33. void consume();
  34. void grow();
  35. void shrink();
  36. };
  37. template <typename T>
  38. struct buffer_sequence_memfns_derived
  39. : T, buffer_sequence_memfns_base
  40. {
  41. };
  42. template <typename T, T>
  43. struct buffer_sequence_memfns_check
  44. {
  45. };
  46. #if defined(BOOST_ASIO_HAS_DECLTYPE)
  47. template <typename>
  48. char buffer_sequence_begin_helper(...);
  49. template <typename T>
  50. char (&buffer_sequence_begin_helper(T* t,
  51. typename enable_if<!is_same<
  52. decltype(boost::asio::buffer_sequence_begin(*t)),
  53. void>::value>::type*))[2];
  54. #else // defined(BOOST_ASIO_HAS_DECLTYPE)
  55. template <typename>
  56. char (&buffer_sequence_begin_helper(...))[2];
  57. template <typename T>
  58. char buffer_sequence_begin_helper(T* t,
  59. buffer_sequence_memfns_check<
  60. void (buffer_sequence_memfns_base::*)(),
  61. &buffer_sequence_memfns_derived<T>::begin>*);
  62. #endif // defined(BOOST_ASIO_HAS_DECLTYPE)
  63. #if defined(BOOST_ASIO_HAS_DECLTYPE)
  64. template <typename>
  65. char buffer_sequence_end_helper(...);
  66. template <typename T>
  67. char (&buffer_sequence_end_helper(T* t,
  68. typename enable_if<!is_same<
  69. decltype(boost::asio::buffer_sequence_end(*t)),
  70. void>::value>::type*))[2];
  71. #else // defined(BOOST_ASIO_HAS_DECLTYPE)
  72. template <typename>
  73. char (&buffer_sequence_end_helper(...))[2];
  74. template <typename T>
  75. char buffer_sequence_end_helper(T* t,
  76. buffer_sequence_memfns_check<
  77. void (buffer_sequence_memfns_base::*)(),
  78. &buffer_sequence_memfns_derived<T>::end>*);
  79. #endif // defined(BOOST_ASIO_HAS_DECLTYPE)
  80. template <typename>
  81. char (&size_memfn_helper(...))[2];
  82. template <typename T>
  83. char size_memfn_helper(
  84. buffer_sequence_memfns_check<
  85. void (buffer_sequence_memfns_base::*)(),
  86. &buffer_sequence_memfns_derived<T>::size>*);
  87. template <typename>
  88. char (&max_size_memfn_helper(...))[2];
  89. template <typename T>
  90. char max_size_memfn_helper(
  91. buffer_sequence_memfns_check<
  92. void (buffer_sequence_memfns_base::*)(),
  93. &buffer_sequence_memfns_derived<T>::max_size>*);
  94. template <typename>
  95. char (&capacity_memfn_helper(...))[2];
  96. template <typename T>
  97. char capacity_memfn_helper(
  98. buffer_sequence_memfns_check<
  99. void (buffer_sequence_memfns_base::*)(),
  100. &buffer_sequence_memfns_derived<T>::capacity>*);
  101. template <typename>
  102. char (&data_memfn_helper(...))[2];
  103. template <typename T>
  104. char data_memfn_helper(
  105. buffer_sequence_memfns_check<
  106. void (buffer_sequence_memfns_base::*)(),
  107. &buffer_sequence_memfns_derived<T>::data>*);
  108. template <typename>
  109. char (&prepare_memfn_helper(...))[2];
  110. template <typename T>
  111. char prepare_memfn_helper(
  112. buffer_sequence_memfns_check<
  113. void (buffer_sequence_memfns_base::*)(),
  114. &buffer_sequence_memfns_derived<T>::prepare>*);
  115. template <typename>
  116. char (&commit_memfn_helper(...))[2];
  117. template <typename T>
  118. char commit_memfn_helper(
  119. buffer_sequence_memfns_check<
  120. void (buffer_sequence_memfns_base::*)(),
  121. &buffer_sequence_memfns_derived<T>::commit>*);
  122. template <typename>
  123. char (&consume_memfn_helper(...))[2];
  124. template <typename T>
  125. char consume_memfn_helper(
  126. buffer_sequence_memfns_check<
  127. void (buffer_sequence_memfns_base::*)(),
  128. &buffer_sequence_memfns_derived<T>::consume>*);
  129. template <typename>
  130. char (&grow_memfn_helper(...))[2];
  131. template <typename T>
  132. char grow_memfn_helper(
  133. buffer_sequence_memfns_check<
  134. void (buffer_sequence_memfns_base::*)(),
  135. &buffer_sequence_memfns_derived<T>::grow>*);
  136. template <typename>
  137. char (&shrink_memfn_helper(...))[2];
  138. template <typename T>
  139. char shrink_memfn_helper(
  140. buffer_sequence_memfns_check<
  141. void (buffer_sequence_memfns_base::*)(),
  142. &buffer_sequence_memfns_derived<T>::shrink>*);
  143. template <typename, typename>
  144. char (&buffer_sequence_element_type_helper(...))[2];
  145. #if defined(BOOST_ASIO_HAS_DECLTYPE)
  146. template <typename T, typename Buffer>
  147. char buffer_sequence_element_type_helper(T* t,
  148. typename enable_if<is_convertible<
  149. decltype(*boost::asio::buffer_sequence_begin(*t)),
  150. Buffer>::value>::type*);
  151. #else // defined(BOOST_ASIO_HAS_DECLTYPE)
  152. template <typename T, typename Buffer>
  153. char buffer_sequence_element_type_helper(
  154. typename T::const_iterator*,
  155. typename enable_if<is_convertible<
  156. typename T::value_type, Buffer>::value>::type*);
  157. #endif // defined(BOOST_ASIO_HAS_DECLTYPE)
  158. template <typename>
  159. char (&const_buffers_type_typedef_helper(...))[2];
  160. template <typename T>
  161. char const_buffers_type_typedef_helper(
  162. typename T::const_buffers_type*);
  163. template <typename>
  164. char (&mutable_buffers_type_typedef_helper(...))[2];
  165. template <typename T>
  166. char mutable_buffers_type_typedef_helper(
  167. typename T::mutable_buffers_type*);
  168. template <typename T, typename Buffer>
  169. struct is_buffer_sequence_class
  170. : integral_constant<bool,
  171. sizeof(buffer_sequence_begin_helper<T>(0, 0)) != 1 &&
  172. sizeof(buffer_sequence_end_helper<T>(0, 0)) != 1 &&
  173. sizeof(buffer_sequence_element_type_helper<T, Buffer>(0, 0)) == 1>
  174. {
  175. };
  176. template <typename T, typename Buffer>
  177. struct is_buffer_sequence
  178. : conditional<is_class<T>::value,
  179. is_buffer_sequence_class<T, Buffer>,
  180. false_type>::type
  181. {
  182. };
  183. template <>
  184. struct is_buffer_sequence<mutable_buffer, mutable_buffer>
  185. : true_type
  186. {
  187. };
  188. template <>
  189. struct is_buffer_sequence<mutable_buffer, const_buffer>
  190. : true_type
  191. {
  192. };
  193. template <>
  194. struct is_buffer_sequence<const_buffer, const_buffer>
  195. : true_type
  196. {
  197. };
  198. template <>
  199. struct is_buffer_sequence<const_buffer, mutable_buffer>
  200. : false_type
  201. {
  202. };
  203. template <typename T>
  204. struct is_dynamic_buffer_class_v1
  205. : integral_constant<bool,
  206. sizeof(size_memfn_helper<T>(0)) != 1 &&
  207. sizeof(max_size_memfn_helper<T>(0)) != 1 &&
  208. sizeof(capacity_memfn_helper<T>(0)) != 1 &&
  209. sizeof(data_memfn_helper<T>(0)) != 1 &&
  210. sizeof(consume_memfn_helper<T>(0)) != 1 &&
  211. sizeof(prepare_memfn_helper<T>(0)) != 1 &&
  212. sizeof(commit_memfn_helper<T>(0)) != 1 &&
  213. sizeof(const_buffers_type_typedef_helper<T>(0)) == 1 &&
  214. sizeof(mutable_buffers_type_typedef_helper<T>(0)) == 1>
  215. {
  216. };
  217. template <typename T>
  218. struct is_dynamic_buffer_v1
  219. : conditional<is_class<T>::value,
  220. is_dynamic_buffer_class_v1<T>,
  221. false_type>::type
  222. {
  223. };
  224. template <typename T>
  225. struct is_dynamic_buffer_class_v2
  226. : integral_constant<bool,
  227. sizeof(size_memfn_helper<T>(0)) != 1 &&
  228. sizeof(max_size_memfn_helper<T>(0)) != 1 &&
  229. sizeof(capacity_memfn_helper<T>(0)) != 1 &&
  230. sizeof(data_memfn_helper<T>(0)) != 1 &&
  231. sizeof(consume_memfn_helper<T>(0)) != 1 &&
  232. sizeof(grow_memfn_helper<T>(0)) != 1 &&
  233. sizeof(shrink_memfn_helper<T>(0)) != 1 &&
  234. sizeof(const_buffers_type_typedef_helper<T>(0)) == 1 &&
  235. sizeof(mutable_buffers_type_typedef_helper<T>(0)) == 1>
  236. {
  237. };
  238. template <typename T>
  239. struct is_dynamic_buffer_v2
  240. : conditional<is_class<T>::value,
  241. is_dynamic_buffer_class_v2<T>,
  242. false_type>::type
  243. {
  244. };
  245. } // namespace detail
  246. } // namespace asio
  247. } // namespace boost
  248. #include <boost/asio/detail/pop_options.hpp>
  249. #endif // BOOST_ASIO_DETAIL_IS_BUFFER_SEQUENCE_HPP