GCC Code Coverage Report


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