1//
2// Copyright (c) 2016-2019 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_DETAIL_BUFFER_TRAITS_HPP
11#define BOOST_BEAST_DETAIL_BUFFER_TRAITS_HPP
12
13#include <boost/asio/buffer.hpp>
14#include <boost/config/workaround.hpp>
15#include <boost/type_traits/make_void.hpp>
16#include <cstdint>
17#include <type_traits>
18
19namespace boost {
20namespace beast {
21namespace detail {
22
23#if BOOST_WORKAROUND(BOOST_MSVC, < 1910)
24
25template<class T>
26struct buffers_iterator_type_helper
27{
28 using type = decltype(
29 net::buffer_sequence_begin(
30 std::declval<T const&>()));
31};
32
33template<>
34struct buffers_iterator_type_helper<
35 net::const_buffer>
36{
37 using type = net::const_buffer const*;
38};
39
40template<>
41struct buffers_iterator_type_helper<
42 net::mutable_buffer>
43{
44 using type = net::mutable_buffer const*;
45};
46
47#endif
48
49struct buffer_bytes_impl
50{
51 std::size_t
52 operator()(net::const_buffer b) const noexcept
53 {
54 return net::const_buffer(b).size();
55 }
56
57 std::size_t
58 operator()(net::mutable_buffer b) const noexcept
59 {
60 return net::mutable_buffer(b).size();
61 }
62
63 template<
64 class B,
65 class = typename std::enable_if<
66 net::is_const_buffer_sequence<B>::value>::type>
67 std::size_t
68 operator()(B const& b) const noexcept
69 {
70 using net::buffer_size;
71 return buffer_size(b);
72 }
73};
74
75/** Return `true` if a buffer sequence is empty
76
77 This is sometimes faster than using @ref buffer_bytes
78*/
79template<class ConstBufferSequence>
80bool
81buffers_empty(ConstBufferSequence const& buffers)
82{
83 auto it = net::buffer_sequence_begin(buffers);
84 auto end = net::buffer_sequence_end(buffers);
85 while(it != end)
86 {
87 if(net::const_buffer(*it).size() > 0)
88 return false;
89 ++it;
90 }
91 return true;
92}
93
94} // detail
95} // beast
96} // boost
97
98#endif
99

source code of boost/libs/beast/include/boost/beast/core/detail/buffer_traits.hpp