GCC Code Coverage Report


Directory: libs/buffers/
File: boost/buffers/const_buffer_pair.hpp
Date: 2024-07-24 21:34:17
Exec Total Coverage
Lines: 24 24 100.0%
Functions: 9 9 100.0%
Branches: 2 4 50.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_CONST_BUFFER_PAIR_HPP
11 #define BOOST_BUFFERS_CONST_BUFFER_PAIR_HPP
12
13 #include <boost/buffers/detail/config.hpp>
14 #include <boost/buffers/const_buffer.hpp>
15 #include <boost/buffers/mutable_buffer_pair.hpp>
16 #include <boost/assert.hpp>
17
18 namespace boost {
19 namespace buffers {
20
21 /** A constant buffer pair
22 */
23 class const_buffer_pair
24 {
25 public:
26 using value_type = const_buffer;
27
28 using const_iterator = value_type const*;
29
30 /** Constructor.
31 */
32 const_buffer_pair() = default;
33
34 /** Constructor.
35 */
36 const_buffer_pair(
37 const_buffer_pair const&) = default;
38
39 /** Constructor.
40 */
41 286606 const_buffer_pair(
42 const_buffer const& b0,
43 const_buffer const& b1) noexcept
44 286606 : b_{ b0, b1 }
45 {
46 286606 }
47
48 /** Constructor.
49 */
50 16 const_buffer_pair(
51 mutable_buffer_pair const& bs) noexcept
52 16 : b_{ bs.begin()[0], bs.begin()[1] }
53 {
54 16 }
55
56 /** Assignment.
57 */
58 const_buffer_pair& operator=(
59 const_buffer_pair const&) = default;
60
61 /** Assignment.
62 */
63 16 const_buffer_pair& operator=(
64 mutable_buffer_pair const& other) noexcept
65 {
66 16 b_[0] = other.begin()[0];
67 16 b_[1] = other.begin()[1];
68 16 return *this;
69 }
70
71 const_buffer const&
72 64 operator[](unsigned i) const noexcept
73 {
74
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
64 BOOST_ASSERT(i < 2);
75 64 return b_[i];
76 }
77
78 const_buffer&
79 64 operator[](unsigned i) noexcept
80 {
81
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
64 BOOST_ASSERT(i < 2);
82 64 return b_[i];
83 }
84
85 const_iterator
86 774271 begin() const noexcept
87 {
88 774271 return b_;
89 }
90
91 const_iterator
92 774270 end() const noexcept
93 {
94 774270 return b_ + 2;
95 }
96
97 friend
98 const_buffer_pair
99 139808 tag_invoke(
100 prefix_tag const&,
101 const_buffer_pair const& b,
102 std::size_t n) noexcept
103 {
104 139808 return b.prefix_impl(n);
105 }
106
107 friend
108 const_buffer_pair
109 139808 tag_invoke(
110 suffix_tag const&,
111 const_buffer_pair const& b,
112 std::size_t n) noexcept
113 {
114 139808 return b.suffix_impl(n);
115 }
116
117 private:
118 BOOST_BUFFERS_DECL
119 const_buffer_pair
120 prefix_impl(
121 std::size_t n) const noexcept;
122
123 BOOST_BUFFERS_DECL
124 const_buffer_pair
125 suffix_impl(
126 std::size_t n) const noexcept;
127
128 const_buffer b_[2];
129 };
130
131 } // buffers
132 } // boost
133
134 #endif
135