mirror of
https://github.com/boostorg/beast.git
synced 2025-07-30 04:47:29 +02:00
Refactor buffers_range:
* Add tests * Increase code coverage * Correct behavior for default constructed iterators
This commit is contained in:
@ -4,6 +4,7 @@ Version 200
|
|||||||
* Tidy up msvc-14 workaround in multi_buffer
|
* Tidy up msvc-14 workaround in multi_buffer
|
||||||
* buffers_cat fixes and coverage
|
* buffers_cat fixes and coverage
|
||||||
* Refactor buffers_adaptor
|
* Refactor buffers_adaptor
|
||||||
|
* Refactor buffers_range
|
||||||
|
|
||||||
API Changes:
|
API Changes:
|
||||||
|
|
||||||
|
@ -46,9 +46,13 @@ public:
|
|||||||
buffer_sequence_iterator<BufferSequence>::type;
|
buffer_sequence_iterator<BufferSequence>::type;
|
||||||
|
|
||||||
iter_type it_;
|
iter_type it_;
|
||||||
|
buffers_range_adaptor const* b_ = nullptr;
|
||||||
|
|
||||||
const_iterator(iter_type const& it)
|
const_iterator(
|
||||||
|
buffers_range_adaptor const& b,
|
||||||
|
iter_type const& it)
|
||||||
: it_(it)
|
: it_(it)
|
||||||
|
, b_(&b)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,17 +64,19 @@ public:
|
|||||||
using difference_type = std::ptrdiff_t;
|
using difference_type = std::ptrdiff_t;
|
||||||
using iterator_category =
|
using iterator_category =
|
||||||
std::bidirectional_iterator_tag;
|
std::bidirectional_iterator_tag;
|
||||||
|
|
||||||
|
const_iterator() = default;
|
||||||
|
|
||||||
bool
|
bool
|
||||||
operator==(const_iterator const& other) const
|
operator==(const_iterator const& other) const
|
||||||
{
|
{
|
||||||
return it_ == other.it_;
|
return b_ == other.b_ && it_ == other.it_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
operator!=(const_iterator const& other) const
|
operator!=(const_iterator const& other) const
|
||||||
{
|
{
|
||||||
return ! (*this == other);
|
return !(*this == other);
|
||||||
}
|
}
|
||||||
|
|
||||||
reference
|
reference
|
||||||
@ -97,7 +103,6 @@ public:
|
|||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// deprecated
|
|
||||||
const_iterator&
|
const_iterator&
|
||||||
operator--()
|
operator--()
|
||||||
{
|
{
|
||||||
@ -105,7 +110,6 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// deprecated
|
|
||||||
const_iterator
|
const_iterator
|
||||||
operator--(int)
|
operator--(int)
|
||||||
{
|
{
|
||||||
@ -121,16 +125,21 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buffers_range_adaptor(
|
||||||
|
buffers_range_adaptor const&) = default;
|
||||||
|
buffers_range_adaptor& operator=(
|
||||||
|
buffers_range_adaptor const&) = default;
|
||||||
|
|
||||||
const_iterator
|
const_iterator
|
||||||
begin() const noexcept
|
begin() const noexcept
|
||||||
{
|
{
|
||||||
return net::buffer_sequence_begin(b_);
|
return {*this, net::buffer_sequence_begin(b_)};
|
||||||
}
|
}
|
||||||
|
|
||||||
const_iterator
|
const_iterator
|
||||||
end() const noexcept
|
end() const noexcept
|
||||||
{
|
{
|
||||||
return net::buffer_sequence_end(b_);
|
return {*this, net::buffer_sequence_end(b_)};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,3 +9,46 @@
|
|||||||
|
|
||||||
// Test that header file is self-contained.
|
// Test that header file is self-contained.
|
||||||
#include <boost/beast/core/buffers_range.hpp>
|
#include <boost/beast/core/buffers_range.hpp>
|
||||||
|
|
||||||
|
#include "buffer_test.hpp"
|
||||||
|
|
||||||
|
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace beast {
|
||||||
|
|
||||||
|
class buffers_range_test : public beast::unit_test::suite
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BOOST_STATIC_ASSERT(
|
||||||
|
net::is_mutable_buffer_sequence<
|
||||||
|
decltype(beast::buffers_range(
|
||||||
|
std::declval<net::mutable_buffer>()))>::value);
|
||||||
|
|
||||||
|
void
|
||||||
|
testBufferSequence()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
string_view s = "Hello, world!";
|
||||||
|
test_buffer_sequence(*this, buffers_range(
|
||||||
|
net::const_buffer{s.data(), s.size()}));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char buf[13];
|
||||||
|
test_buffer_sequence(*this,
|
||||||
|
buffers_range(net::mutable_buffer{
|
||||||
|
buf, sizeof(buf)}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
run() override
|
||||||
|
{
|
||||||
|
testBufferSequence();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
BEAST_DEFINE_TESTSUITE(beast,core,buffers_range);
|
||||||
|
|
||||||
|
} // beast
|
||||||
|
} // boost
|
||||||
|
Reference in New Issue
Block a user