GCC Code Coverage Report


Directory: libs/buffers/
File: boost/buffers/buffer_size.hpp
Date: 2024-04-15 19:09:27
Exec Total Coverage
Lines: 7 7 100.0%
Functions: 13 13 100.0%
Branches: 3 3 100.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_BUFFER_SIZE_HPP
11 #define BOOST_BUFFERS_BUFFER_SIZE_HPP
12
13 #include <boost/buffers/detail/config.hpp>
14 #include <boost/buffers/const_buffer.hpp>
15 #include <boost/buffers/range.hpp>
16 #include <boost/buffers/tag_invoke.hpp>
17 #include <boost/buffers/type_traits.hpp>
18
19 namespace boost {
20 namespace buffers {
21
22 template<class Buffers>
23 std::size_t
24 1147900 tag_invoke(
25 size_tag const&,
26 Buffers const& bs) noexcept
27 {
28 1147900 std::size_t n = 0;
29
3/3
✓ Branch 3 taken 878227 times.
✓ Branch 4 taken 981450 times.
✓ Branch 5 taken 279362 times.
2853893 for(const_buffer b : range(bs))
30 1705993 n += b.size();
31 1147900 return n;
32 }
33
34 namespace detail {
35
36 struct buffer_size_impl
37 {
38 template<class Buffers>
39 std::size_t
40 857994 operator()(
41 Buffers const& bs) const noexcept
42 {
43 // If you get a compile error here it
44 // means that your type does not meet
45 // the requirements.
46 static_assert(
47 is_const_buffer_sequence<Buffers>::value,
48 "Type requirements not met.");
49
50 857994 return tag_invoke(size_tag{}, bs);
51 }
52 };
53
54 } // detail
55
56 /** Return the total octets in a buffer sequence
57
58 @par Constraints
59 @code
60 is_const_buffer_sequence< ConstBufferSequence >::value == true
61 @endcode
62 */
63 constexpr detail::buffer_size_impl buffer_size{};
64
65 } // buffers
66 } // boost
67
68 #endif
69