Tidy up some buffer sequence iterators

This commit is contained in:
Vinnie Falco
2018-12-23 08:43:27 -08:00
parent 92e598ade3
commit 7caa0b8132
9 changed files with 70 additions and 44 deletions

View File

@ -2,6 +2,7 @@ Version 201
* Decay bound arguments in handler wrapper parameters
* Add bind_back_handler
* Tidy up default-constructed iterators
--------------------------------------------------------------------------------

View File

@ -39,9 +39,9 @@ class buffers_prefix_view
buffers_iterator_type<BufferSequence>;
BufferSequence bs_;
std::size_t size_;
std::size_t remain_;
iter_type end_;
std::size_t size_ = 0;
std::size_t remain_ = 0;
iter_type end_{};
void
setup(std::size_t size);

View File

@ -56,7 +56,7 @@ class buffers_suffix
buffers_iterator_type<BufferSequence>;
BufferSequence bs_;
iter_type begin_;
iter_type begin_{};
std::size_t skip_ = 0;
template<class Deduced>
@ -124,7 +124,7 @@ public:
explicit
buffers_suffix(boost::in_place_init_t, Args&&... args);
/// Assignment
/// Copy Assignment
buffers_suffix& operator=(buffers_suffix const&);
/// Get a bidirectional iterator to the first element.

View File

@ -37,7 +37,7 @@ public:
using iter_type =
buffers_iterator_type<BufferSequence>;
iter_type it_;
iter_type it_{};
buffers_range_adaptor const* b_ = nullptr;
const_iterator(

View File

@ -97,7 +97,7 @@ class buffers_cat_view<Bn...>::const_iterator
detail::tuple<Bn...> const* bn_ = nullptr;
detail::variant<
buffers_iterator_type<Bn>..., past_end> it_;
buffers_iterator_type<Bn>..., past_end> it_{};
friend class buffers_cat_view<Bn...>;
@ -105,8 +105,8 @@ class buffers_cat_view<Bn...>::const_iterator
using C = std::integral_constant<std::size_t, I>;
public:
using value_type =
typename buffers_cat_view<Bn...>::value_type;
using value_type = typename
buffers_cat_view<Bn...>::value_type;
using pointer = value_type const*;
using reference = value_type;
using difference_type = std::ptrdiff_t;
@ -115,7 +115,8 @@ public:
const_iterator() = default;
const_iterator(const_iterator const& other) = default;
const_iterator& operator=(const_iterator const& other) = default;
const_iterator& operator=(
const_iterator const& other) = default;
bool
operator==(const_iterator const& other) const;
@ -146,7 +147,12 @@ public:
private:
const_iterator(
detail::tuple<Bn...> const& bn, bool at_end);
detail::tuple<Bn...> const& bn,
std::true_type);
const_iterator(
detail::tuple<Bn...> const& bn,
std::false_type);
struct dereference
{
@ -308,21 +314,27 @@ template<class... Bn>
buffers_cat_view<Bn...>::
const_iterator::
const_iterator(
detail::tuple<Bn...> const& bn, bool at_end)
detail::tuple<Bn...> const& bn,
std::true_type)
: bn_(&bn)
{
// one past the end
it_.template emplace<sizeof...(Bn)+1>();
}
template<class... Bn>
buffers_cat_view<Bn...>::
const_iterator::
const_iterator(
detail::tuple<Bn...> const& bn,
std::false_type)
: bn_(&bn)
{
if(! at_end)
{
it_.template emplace<1>(
net::buffer_sequence_begin(
detail::get<0>(*bn_)));
increment{*this}.next(
mp11::mp_size_t<1>{});
}
else
{
it_.template emplace<sizeof...(Bn)+1>();
}
}
template<class... Bn>
@ -414,7 +426,7 @@ auto
buffers_cat_view<Bn...>::begin() const ->
const_iterator
{
return const_iterator{bn_, false};
return const_iterator{bn_, std::false_type{}};
}
template<class... Bn>
@ -422,7 +434,7 @@ auto
buffers_cat_view<Bn...>::end() const->
const_iterator
{
return const_iterator{bn_, true};
return const_iterator{bn_, std::true_type{}};
}
} // beast

View File

@ -28,7 +28,7 @@ class buffers_prefix_view<Buffers>::const_iterator
buffers_prefix_view const* b_ = nullptr;
std::size_t remain_ = 0;
iter_type it_;
iter_type it_{};
public:
#if BOOST_WORKAROUND(BOOST_MSVC, < 1910)
@ -53,8 +53,10 @@ public:
std::bidirectional_iterator_tag;
const_iterator() = default;
const_iterator(const_iterator const& other) = default;
const_iterator& operator=(const_iterator const& other) = default;
const_iterator(
const_iterator const& other) = default;
const_iterator& operator=(
const_iterator const& other) = default;
bool
operator==(const_iterator const& other) const
@ -72,8 +74,9 @@ public:
operator*() const
{
value_type v(*it_);
return { v.data(),
remain_ < v.size() ? remain_ : v.size()};
if(remain_ < v.size())
return {v.data(), remain_};
return v;
}
pointer

View File

@ -28,7 +28,7 @@ class buffers_suffix<Buffers>::const_iterator
using iter_type = buffers_iterator_type<Buffers>;
iter_type it_;
iter_type it_{};
buffers_suffix const* b_ = nullptr;
public:
@ -49,8 +49,10 @@ public:
std::bidirectional_iterator_tag;
const_iterator() = default;
const_iterator(const_iterator const& other) = default;
const_iterator& operator=(const_iterator const& other) = default;
const_iterator(
const_iterator const& other) = default;
const_iterator& operator=(
const_iterator const& other) = default;
bool
operator==(const_iterator const& other) const
@ -67,9 +69,15 @@ public:
reference
operator*() const
{
#if 0
if(it_ == b_->begin_)
return value_type(*it_) + b_->skip_;
return value_type{*it_} + b_->skip_;
return value_type{*it_};
#else
return it_ == b_->begin_
? value_type{*it_} + b_->skip_
: *it_;
#endif
}
pointer
@ -141,7 +149,7 @@ buffers_suffix(Buffers const& bs)
, begin_(net::buffer_sequence_begin(bs_))
{
static_assert(
net::is_const_buffer_sequence<Buffers>::value||
net::is_const_buffer_sequence<Buffers>::value ||
net::is_mutable_buffer_sequence<Buffers>::value,
"BufferSequence requirements not met");
}
@ -200,13 +208,12 @@ void
buffers_suffix<Buffers>::
consume(std::size_t amount)
{
using net::buffer_size;
auto const end =
net::buffer_sequence_end(bs_);
for(;amount > 0 && begin_ != end; ++begin_)
{
auto const len =
buffer_size(*begin_) - skip_;
net::buffer_size(*begin_) - skip_;
if(amount < len)
{
skip_ += amount;

View File

@ -229,12 +229,14 @@ public:
std::bidirectional_iterator_tag;
const_iterator() = default;
const_iterator(const_iterator const& other) = default;
const_iterator& operator=(const_iterator const& other) = default;
const_iterator(
const_iterator const& other) = default;
const_iterator& operator=(
const_iterator const& other) = default;
const_iterator(
basic_multi_buffer const& b,
typename list_type::const_iterator const& it) noexcept
basic_multi_buffer const& b, typename
list_type::const_iterator const& it) noexcept
: b_(&b)
, it_(it)
{

View File

@ -294,7 +294,8 @@ public:
// VFALCO Some version of g++ incorrectly complain about
// uninitialized values when buffers_cat and
// buffers_prefix are used together.
// buffers_prefix and/or buffers_suffix are used
// together.
void
testGccWarning2()
{