diff --git a/CHANGELOG.md b/CHANGELOG.md index c90249bf..5e5be9ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Version 201 * Decay bound arguments in handler wrapper parameters * Add bind_back_handler +* Tidy up default-constructed iterators -------------------------------------------------------------------------------- diff --git a/include/boost/beast/core/buffers_prefix.hpp b/include/boost/beast/core/buffers_prefix.hpp index 76a034e3..57c6eb38 100644 --- a/include/boost/beast/core/buffers_prefix.hpp +++ b/include/boost/beast/core/buffers_prefix.hpp @@ -39,9 +39,9 @@ class buffers_prefix_view buffers_iterator_type; 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); diff --git a/include/boost/beast/core/buffers_suffix.hpp b/include/boost/beast/core/buffers_suffix.hpp index acd45888..3d905058 100644 --- a/include/boost/beast/core/buffers_suffix.hpp +++ b/include/boost/beast/core/buffers_suffix.hpp @@ -56,7 +56,7 @@ class buffers_suffix buffers_iterator_type; BufferSequence bs_; - iter_type begin_; + iter_type begin_{}; std::size_t skip_ = 0; template @@ -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. diff --git a/include/boost/beast/core/detail/buffers_range_adaptor.hpp b/include/boost/beast/core/detail/buffers_range_adaptor.hpp index 3c9d75f5..36395f90 100644 --- a/include/boost/beast/core/detail/buffers_range_adaptor.hpp +++ b/include/boost/beast/core/detail/buffers_range_adaptor.hpp @@ -37,7 +37,7 @@ public: using iter_type = buffers_iterator_type; - iter_type it_; + iter_type it_{}; buffers_range_adaptor const* b_ = nullptr; const_iterator( diff --git a/include/boost/beast/core/impl/buffers_cat.hpp b/include/boost/beast/core/impl/buffers_cat.hpp index 1e729a8f..f2e3c679 100644 --- a/include/boost/beast/core/impl/buffers_cat.hpp +++ b/include/boost/beast/core/impl/buffers_cat.hpp @@ -97,7 +97,7 @@ class buffers_cat_view::const_iterator detail::tuple const* bn_ = nullptr; detail::variant< - buffers_iterator_type..., past_end> it_; + buffers_iterator_type..., past_end> it_{}; friend class buffers_cat_view; @@ -105,8 +105,8 @@ class buffers_cat_view::const_iterator using C = std::integral_constant; public: - using value_type = - typename buffers_cat_view::value_type; + using value_type = typename + buffers_cat_view::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 const& bn, bool at_end); + detail::tuple const& bn, + std::true_type); + + const_iterator( + detail::tuple const& bn, + std::false_type); struct dereference { @@ -259,7 +265,7 @@ private: for(;;) { if(it == net::buffer_sequence_begin( - detail::get(*self.bn_))) + detail::get(*self.bn_))) { BOOST_BEAST_LOGIC_ERROR( "Decrementing an iterator to the beginning"); @@ -308,21 +314,27 @@ template buffers_cat_view:: const_iterator:: const_iterator( - detail::tuple const& bn, bool at_end) + detail::tuple const& bn, + std::true_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(); - } + // one past the end + it_.template emplace(); +} + +template +buffers_cat_view:: +const_iterator:: +const_iterator( + detail::tuple const& bn, + std::false_type) + : bn_(&bn) +{ + it_.template emplace<1>( + net::buffer_sequence_begin( + detail::get<0>(*bn_))); + increment{*this}.next( + mp11::mp_size_t<1>{}); } template @@ -414,7 +426,7 @@ auto buffers_cat_view::begin() const -> const_iterator { - return const_iterator{bn_, false}; + return const_iterator{bn_, std::false_type{}}; } template @@ -422,7 +434,7 @@ auto buffers_cat_view::end() const-> const_iterator { - return const_iterator{bn_, true}; + return const_iterator{bn_, std::true_type{}}; } } // beast diff --git a/include/boost/beast/core/impl/buffers_prefix.hpp b/include/boost/beast/core/impl/buffers_prefix.hpp index 36f21ab4..06ef4989 100644 --- a/include/boost/beast/core/impl/buffers_prefix.hpp +++ b/include/boost/beast/core/impl/buffers_prefix.hpp @@ -28,7 +28,7 @@ class buffers_prefix_view::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 diff --git a/include/boost/beast/core/impl/buffers_suffix.hpp b/include/boost/beast/core/impl/buffers_suffix.hpp index 0dfb488d..72df82e1 100644 --- a/include/boost/beast/core/impl/buffers_suffix.hpp +++ b/include/boost/beast/core/impl/buffers_suffix.hpp @@ -28,7 +28,7 @@ class buffers_suffix::const_iterator using iter_type = buffers_iterator_type; - 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::value|| + net::is_const_buffer_sequence::value || net::is_mutable_buffer_sequence::value, "BufferSequence requirements not met"); } @@ -200,13 +208,12 @@ void buffers_suffix:: 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; diff --git a/include/boost/beast/core/impl/multi_buffer.hpp b/include/boost/beast/core/impl/multi_buffer.hpp index dd18189c..6f119702 100644 --- a/include/boost/beast/core/impl/multi_buffer.hpp +++ b/include/boost/beast/core/impl/multi_buffer.hpp @@ -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) { diff --git a/test/beast/core/buffers_cat.cpp b/test/beast/core/buffers_cat.cpp index 78236353..dded6e7e 100644 --- a/test/beast/core/buffers_cat.cpp +++ b/test/beast/core/buffers_cat.cpp @@ -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() {