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 | 1147901 | tag_invoke( | |
25 | size_tag const&, | ||
26 | Buffers const& bs) noexcept | ||
27 | { | ||
28 | 1147901 | std::size_t n = 0; | |
29 |
5/5✓ Branch 3 taken 873342 times.
✓ Branch 4 taken 580954 times.
✓ Branch 5 taken 404678 times.
✓ Branch 6 taken 279650 times.
✓ Branch 7 taken 417 times.
|
2853895 | for(const_buffer b : range(bs)) |
30 | 1705994 | n += b.size(); | |
31 | 1147901 | return n; | |
32 | } | ||
33 | |||
34 | namespace detail { | ||
35 | |||
36 | struct buffer_size_impl | ||
37 | { | ||
38 | template<class Buffers> | ||
39 | std::size_t | ||
40 | 857995 | 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 | 857995 | 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 |