liuxiaolong
2021-07-20 58d904a328c0d849769b483e901a0be9426b8209
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/boostorg/beast
//
 
#ifndef BOOST_BEAST_DETAIL_BUFFERS_RANGE_ADAPTOR_HPP
#define BOOST_BEAST_DETAIL_BUFFERS_RANGE_ADAPTOR_HPP
 
#include <boost/beast/core/buffer_traits.hpp>
#include <iterator>
#include <type_traits>
 
namespace boost {
namespace beast {
namespace detail {
 
template<class BufferSequence>
class buffers_range_adaptor
{
    BufferSequence b_;
 
public:
#if BOOST_BEAST_DOXYGEN
    using value_type = __see_below__;
#else
    using value_type = buffers_type<BufferSequence>;
#endif
 
    class const_iterator
    {
        friend class buffers_range_adaptor;
 
        using iter_type =
            buffers_iterator_type<BufferSequence>;
 
        iter_type it_{};
 
        const_iterator(iter_type const& it)
            : it_(it)
        {
        }
 
    public:
        using value_type = typename
            buffers_range_adaptor::value_type;
        using pointer = value_type const*;
        using reference = value_type;
        using difference_type = std::ptrdiff_t;
        using iterator_category =
            std::bidirectional_iterator_tag;
 
        const_iterator() = default;
 
        bool
        operator==(const_iterator const& other) const
        {
            return it_ == other.it_;
        }
 
        bool
        operator!=(const_iterator const& other) const
        {
            return !(*this == other);
        }
 
        reference
        operator*() const
        {
            return *it_;
        }
 
        pointer
        operator->() const = delete;
 
        const_iterator&
        operator++()
        {
            ++it_;
            return *this;
        }
 
        const_iterator
        operator++(int)
        {
            auto temp = *this;
            ++(*this);
            return temp;
        }
 
        const_iterator&
        operator--()
        {
            --it_;
            return *this;
        }
 
        const_iterator
        operator--(int)
        {
            auto temp = *this;
            --(*this);
            return temp;
        }
    };
 
    explicit
    buffers_range_adaptor(BufferSequence const& b)
        : b_(b)
    {
    }
 
    const_iterator
    begin() const noexcept
    {
        return {net::buffer_sequence_begin(b_)};
    }
 
    const_iterator
    end() const noexcept
    {
        return {net::buffer_sequence_end(b_)};
    }
};
 
} // detail
} // beast
} // boost
 
#endif