include/boost/capy/buffers/buffers_front.hpp

100.0% Lines (10 / 10) 100.0% Functions (5 / 5)
buffers_front.hpp
f(x) Functions (5)
Line TLA Hits Source Code
1 //
2 // Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com)
3 // Copyright (c) 2026 Steve Gerbino
4 //
5 // Distributed under the Boost Software License, Version 1.0. (See accompanying
6 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // Official repository: https://github.com/cppalliance/capy
9 //
10
11 #ifndef BOOST_CAPY_BUFFERS_BUFFERS_FRONT_HPP
12 #define BOOST_CAPY_BUFFERS_BUFFERS_FRONT_HPP
13
14 #include <boost/capy/detail/config.hpp>
15 #include <boost/capy/buffers.hpp>
16
17 namespace boost {
18 namespace capy {
19
20 // MrDocs 0.8.0 flags this object as `buffers_front: variable is
21 // undocumented`, as it does the other five buffer CPOs
22 // (buffer_sequence_begin, buffer_sequence_end, buffer_size, buffers_empty,
23 // buffer_copy). The finding is grandfathered in doc/lint/baseline.json.
24 // Silencing it buys nothing: on the synthesised overload page MrDocs renders
25 // neither the record-level docstring below nor one attached to the variable,
26 // so any docstring that clears the warning is invisible to readers. It
27 // would be a second, dead copy of this prose. Verified twice against the built site.
28 /** Return the first buffer in a sequence.
29
30 @functionobject
31 */
32 constexpr struct
33 {
34 /** Return the first mutable buffer, or an empty buffer.
35
36 @param bs The buffer sequence to inspect.
37
38 @return The first buffer in `bs`, or an empty buffer if none.
39 */
40 template<MutableBufferSequence MutableBufferSequence>
41 mutable_buffer
42 5x operator()(
43 MutableBufferSequence const& bs) const noexcept
44 {
45 5x auto const it = buffer_sequence_begin(bs);
46 5x if(it != buffer_sequence_end(bs))
47 4x return *it;
48 1x return {};
49 }
50
51 /** Return the first const buffer, or an empty buffer.
52
53 @param bs The buffer sequence to inspect.
54
55 @return The first buffer in `bs`, or an empty buffer if none.
56 */
57 template<ConstBufferSequence ConstBufferSequence>
58 const_buffer
59 5x operator()(
60 ConstBufferSequence const& bs) const noexcept
61 {
62 5x auto const it = buffer_sequence_begin(bs);
63 5x if(it != buffer_sequence_end(bs))
64 4x return *it;
65 1x return {};
66 }
67 } const buffers_front{};
68
69 } // capy
70 } // boost
71
72 #endif
73