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_BUFFERS_RANGE_ADAPTOR_HPP
11#define BOOST_BEAST_DETAIL_BUFFERS_RANGE_ADAPTOR_HPP
12
13#include <boost/beast/core/buffer_traits.hpp>
14#include <iterator>
15#include <type_traits>
16
17namespace boost {
18namespace beast {
19namespace detail {
20
21template<class BufferSequence>
22class buffers_range_adaptor
23{
24 BufferSequence b_;
25
26public:
27#if BOOST_BEAST_DOXYGEN
28 using value_type = __see_below__;
29#else
30 using value_type = buffers_type<BufferSequence>;
31#endif
32
33 class const_iterator
34 {
35 friend class buffers_range_adaptor;
36
37 using iter_type =
38 buffers_iterator_type<BufferSequence>;
39
40 iter_type it_{};
41
42 const_iterator(iter_type const& it)
43 : it_(it)
44 {
45 }
46
47 public:
48 using value_type = typename
49 buffers_range_adaptor::value_type;
50 using pointer = value_type const*;
51 using reference = value_type;
52 using difference_type = std::ptrdiff_t;
53 using iterator_category =
54 std::bidirectional_iterator_tag;
55
56 const_iterator() = default;
57
58 bool
59 operator==(const_iterator const& other) const
60 {
61 return it_ == other.it_;
62 }
63
64 bool
65 operator!=(const_iterator const& other) const
66 {
67 return !(*this == other);
68 }
69
70 reference
71 operator*() const
72 {
73 return *it_;
74 }
75
76 pointer
77 operator->() const = delete;
78
79 const_iterator&
80 operator++()
81 {
82 ++it_;
83 return *this;
84 }
85
86 const_iterator
87 operator++(int)
88 {
89 auto temp = *this;
90 ++(*this);
91 return temp;
92 }
93
94 const_iterator&
95 operator--()
96 {
97 --it_;
98 return *this;
99 }
100
101 const_iterator
102 operator--(int)
103 {
104 auto temp = *this;
105 --(*this);
106 return temp;
107 }
108 };
109
110 explicit
111 buffers_range_adaptor(BufferSequence const& b)
112 : b_(b)
113 {
114 }
115
116 const_iterator
117 begin() const noexcept
118 {
119 return {net::buffer_sequence_begin(b_)};
120 }
121
122 const_iterator
123 end() const noexcept
124 {
125 return {net::buffer_sequence_end(b_)};
126 }
127};
128
129} // detail
130} // beast
131} // boost
132
133#endif
134

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