GCC Code Coverage Report


Directory: libs/buffers/
File: boost/buffers/impl/mutable_buffer_subspan.hpp
Date: 2024-07-24 21:34:17
Exec Total Coverage
Lines: 39 39 100.0%
Functions: 10 10 100.0%
Branches: 14 20 70.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.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/cppalliance/buffers
8 //
9
10 #ifndef BOOST_BUFFERS_IMPL_MUTABLE_BUFFER_SUBSPAN_HPP
11 #define BOOST_BUFFERS_IMPL_MUTABLE_BUFFER_SUBSPAN_HPP
12
13 #include <boost/assert.hpp>
14 #include <iterator>
15
16 namespace boost {
17 namespace buffers {
18
19 class mutable_buffer_subspan::
20 const_iterator
21 {
22 mutable_buffer_subspan const* s_ = nullptr;
23 std::size_t i_ = 0;
24
25 friend class mutable_buffer_subspan;
26
27 2786 const_iterator(
28 mutable_buffer_subspan const& s,
29 std::size_t i) noexcept
30 2786 : s_(&s)
31 2786 , i_(i)
32 {
33 2786 }
34
35 public:
36 using value_type = mutable_buffer;
37 using reference = mutable_buffer;
38 using pointer = void;
39 using difference_type = std::ptrdiff_t;
40 using iterator_category =
41 std::bidirectional_iterator_tag;
42
43 const_iterator() = default;
44 const_iterator(
45 const_iterator const&) = default;
46 const_iterator& operator=(
47 const_iterator const&) = default;
48
49 bool
50 3648 operator==(
51 const_iterator const& other) const noexcept
52 {
53 return
54
1/2
✓ Branch 0 taken 3648 times.
✗ Branch 1 not taken.
7296 s_ == other.s_ &&
55
2/2
✓ Branch 0 taken 1393 times.
✓ Branch 1 taken 2255 times.
7296 i_ == other.i_;
56 }
57
58 bool
59 3648 operator!=(
60 const_iterator const& other) const noexcept
61 {
62 3648 return !(*this == other);
63 }
64
65 BOOST_BUFFERS_DECL
66 reference
67 operator*() const noexcept;
68
69 const_iterator&
70 2231 operator++() noexcept
71 {
72
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2231 times.
2231 BOOST_ASSERT(i_ < s_->n_);
73 2231 ++i_;
74 2231 return *this;
75 }
76
77 const_iterator
78 12 operator++(int) noexcept
79 {
80 12 auto temp = *this;
81 12 ++(*this);
82 12 return temp;
83 }
84
85 const_iterator&
86 24 operator--() noexcept
87 {
88
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 BOOST_ASSERT(i_ > 0);
89 24 --i_;
90 24 return *this;
91 }
92
93 const_iterator
94 12 operator--(int) noexcept
95 {
96 12 auto temp = *this;
97 12 --(*this);
98 12 return temp;
99 }
100 };
101
102 //------------------------------------------------
103
104 1287 mutable_buffer_subspan::
105 mutable_buffer_subspan(
106 mutable_buffer const* p,
107 std::size_t n,
108 std::size_t p0,
109 1287 std::size_t p1) noexcept
110 1287 : p_(p)
111 1287 , n_(n)
112 1287 , p0_(p0)
113 1287 , p1_(p1)
114 {
115
3/4
✓ Branch 0 taken 521 times.
✓ Branch 1 taken 766 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 521 times.
1287 BOOST_ASSERT(
116 n_ > 1 ||
117 p1_ >= p0_);
118
3/4
✓ Branch 0 taken 1199 times.
✓ Branch 1 taken 88 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1199 times.
1287 BOOST_ASSERT(
119 n_ == 0 ||
120 p0 < p[0].size());
121
3/4
✓ Branch 0 taken 1199 times.
✓ Branch 1 taken 88 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1199 times.
1287 BOOST_ASSERT(
122 n_ == 0 ||
123 p1 <= p[n_ - 1].size());
124 1287 }
125
126 auto
127 1393 mutable_buffer_subspan::
128 begin() const noexcept ->
129 const_iterator
130 {
131 1393 return { *this, 0 };
132 }
133
134 auto
135 1393 mutable_buffer_subspan::
136 end() const noexcept ->
137 const_iterator
138 {
139 1393 return { *this, n_ };
140 }
141
142 } // buffers
143 } // boost
144
145 #endif
146