This is an automated email from the ASF dual-hosted git repository. bneradt pushed a commit to branch dev-1-0-14 in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git
commit 9f8ee6348da09c5a0c4233dace20eaf1857d6e5d Author: Alan M. Carroll <[email protected]> AuthorDate: Tue Mar 3 07:10:38 2020 -0600 Added copy constructor & assignment for IPSpace iterators. --- swoc++/include/swoc/swoc_ip.h | 36 ++++++++++++++++++++++++++++++++++++ unit_tests/test_ip.cc | 11 +++++++++++ 2 files changed, 47 insertions(+) diff --git a/swoc++/include/swoc/swoc_ip.h b/swoc++/include/swoc/swoc_ip.h index 7fe13b3..4d40e3f 100644 --- a/swoc++/include/swoc/swoc_ip.h +++ b/swoc++/include/swoc/swoc_ip.h @@ -1497,6 +1497,12 @@ public: /// Default constructor. const_iterator() = default; + /// Copy constructor. + const_iterator(self_type const& that); + + /// Assignment. + self_type & operator=(self_type const& that); + /// Pre-increment. /// Move to the next element in the list. /// @return The iterator. @@ -1579,6 +1585,12 @@ public: /// Default constructor. iterator() = default; + /// Copy constructor. + iterator(self_type const& that); + + /// Assignment. + self_type & operator=(self_type const& that); + /// Pre-increment. /// Move to the next element in the list. /// @return The iterator. @@ -1645,6 +1657,19 @@ IPSpace<PAYLOAD>::const_iterator::const_iterator(typename IP4Space::iterator con } } +template<typename PAYLOAD> +IPSpace<PAYLOAD>::const_iterator::const_iterator(self_type const& that) { + *this = that; +} + +template<typename PAYLOAD> +auto IPSpace<PAYLOAD>::const_iterator::operator=(self_type const& that) -> self_type &{ + _iter_4 = that._iter_4; + _iter_6 = that._iter_6; + new(&_value) value_type{that._value}; + return *this; +} + template<typename PAYLOAD> auto IPSpace<PAYLOAD>::const_iterator::operator++() -> self_type& { bool incr_p = false; @@ -1723,6 +1748,17 @@ IPSpace<PAYLOAD>::const_iterator::operator!=(self_type const& that) const { return _iter_4 != that._iter_4 || _iter_6 != that._iter_6; } +template<typename PAYLOAD> +IPSpace<PAYLOAD>::iterator::iterator(self_type const& that) { + *this = that; +} + +template<typename PAYLOAD> +auto IPSpace<PAYLOAD>::iterator::operator=(self_type const& that) -> self_type & { + this->super_type::operator=(that); + return *this; +} + template<typename PAYLOAD> auto IPSpace<PAYLOAD>::iterator::operator->() const -> value_type const * { return static_cast<value_type *>(&super_type::_value); diff --git a/unit_tests/test_ip.cc b/unit_tests/test_ip.cc index 39616aa..e9e3e8e 100644 --- a/unit_tests/test_ip.cc +++ b/unit_tests/test_ip.cc @@ -709,6 +709,17 @@ TEST_CASE("IPSpace docJJ", "[libswoc][ipspace][docJJ]") { --idx; CHECK(bits == make_bits(results[idx])); } + + // Check iterator copying. + idx = 0; + Space::iterator iter; + for (auto spot = space.begin(); spot != space.end() ; ++spot) { + iter = spot; + auto const& [range, bits]{*iter}; + REQUIRE(idx < results.size()); + CHECK(bits == make_bits(results[idx])); + ++idx; + } } #if 0
