forked from boostorg/beast
Refactor buffers_prefix:
* Tidy up tests * Increase code coverage * Correct behavior for default constructed iterators
This commit is contained in:
1 parent
719fe66b77
commit
4cfe860b93
5 files changed
+89
-177
No files matched your search
@@ -11,8 +11,8 @@
|
||||
#define BOOST_BEAST_BUFFERS_PREFIX_HPP
|
||||
|
||||
#include <boost/beast/core/detail/config.hpp>
|
||||
#include <boost/beast/core/buffer_traits.hpp>
|
||||
#include <boost/beast/core/type_traits.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/optional/optional.hpp> // for in_place_init_t
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
@@ -49,13 +49,19 @@ class buffers_prefix_view
|
||||
std::size_t dist);
|
||||
|
||||
public:
|
||||
/// The type for each element in the list of buffers.
|
||||
using value_type = typename std::conditional<
|
||||
std::is_convertible<typename
|
||||
std::iterator_traits<iter_type>::value_type,
|
||||
net::mutable_buffer>::value,
|
||||
net::mutable_buffer,
|
||||
net::const_buffer>::type;
|
||||
/** The type for each element in the list of buffers.
|
||||
|
||||
If the type of the underlying sequence is a mutable buffer
|
||||
sequence, then `value_type` is `net::mutable_buffer`. Otherwise,
|
||||
`value_type` is `net::const_buffer`.
|
||||
|
||||
@see buffers_type
|
||||
*/
|
||||
#if BOOST_BEAST_DOXYGEN
|
||||
using value_type = __see_below__;
|
||||
#else
|
||||
using value_type = buffers_type<ConstBufferSequence>;
|
||||
#endif
|
||||
|
||||
#if BOOST_BEAST_DOXYGEN
|
||||
/// A bidirectional iterator type that may be used to read elements.
|
||||
|
||||
@@ -26,7 +26,7 @@ class buffers_prefix_view<Buffers>::const_iterator
|
||||
friend class buffers_prefix_view<Buffers>;
|
||||
|
||||
buffers_prefix_view const* b_ = nullptr;
|
||||
std::size_t remain_;
|
||||
std::size_t remain_ = 0;
|
||||
iter_type it_;
|
||||
|
||||
public:
|
||||
@@ -49,20 +49,7 @@ public:
|
||||
bool
|
||||
operator==(const_iterator const& other) const
|
||||
{
|
||||
return
|
||||
(b_ == nullptr) ?
|
||||
(
|
||||
other.b_ == nullptr ||
|
||||
other.it_ == other.b_->end_
|
||||
):(
|
||||
(other.b_ == nullptr) ?
|
||||
(
|
||||
it_ == b_->end_
|
||||
): (
|
||||
b_ == other.b_ &&
|
||||
it_ == other.it_
|
||||
)
|
||||
);
|
||||
return b_ == other.b_ && it_ == other.it_;
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -111,16 +98,18 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
const_iterator(buffers_prefix_view const& b,
|
||||
std::true_type)
|
||||
const_iterator(
|
||||
buffers_prefix_view const& b,
|
||||
std::true_type)
|
||||
: b_(&b)
|
||||
, remain_(b.remain_)
|
||||
, it_(b_->end_)
|
||||
{
|
||||
}
|
||||
|
||||
const_iterator(buffers_prefix_view const& b,
|
||||
std::false_type)
|
||||
const_iterator(
|
||||
buffers_prefix_view const& b,
|
||||
std::false_type)
|
||||
: b_(&b)
|
||||
, remain_(b_->size_)
|
||||
, it_(net::buffer_sequence_begin(b_->bs_))
|
||||
@@ -222,18 +211,22 @@ buffers_prefix_view(
|
||||
|
||||
template<class Buffers>
|
||||
auto
|
||||
buffers_prefix_view<Buffers>::begin() const ->
|
||||
buffers_prefix_view<Buffers>::
|
||||
begin() const ->
|
||||
const_iterator
|
||||
{
|
||||
return const_iterator{*this, std::false_type{}};
|
||||
return const_iterator{
|
||||
*this, std::false_type{}};
|
||||
}
|
||||
|
||||
template<class Buffers>
|
||||
auto
|
||||
buffers_prefix_view<Buffers>::end() const ->
|
||||
buffers_prefix_view<Buffers>::
|
||||
end() const ->
|
||||
const_iterator
|
||||
{
|
||||
return const_iterator{*this, std::true_type{}};
|
||||
return const_iterator{
|
||||
*this, std::true_type{}};
|
||||
}
|
||||
|
||||
template<class Buffers>
|
||||
|
||||
Reference in new issue
Block a user