diff --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count.pass.cpp --- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count.pass.cpp +++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count.pass.cpp @@ -26,7 +26,7 @@ auto first = stride_counting_iterator(It(range.begin())); std::ranges::advance(first, n); - assert(first.base().base() == range.begin() + n); + assert(base(base(first)) == range.begin() + n); if constexpr (std::random_access_iterator) { assert(first.stride_count() == 0 || first.stride_count() == 1); assert(first.stride_displacement() == 1); @@ -41,7 +41,7 @@ auto range = range_t{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; auto first = stride_counting_iterator(It(range.begin() + n)); std::ranges::advance(first, -n); - assert(first.base().base() == range.begin()); + assert(base(base(first)) == range.begin()); if constexpr (std::random_access_iterator) { assert(first.stride_count() == 0 || first.stride_count() == 1); diff --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count_sentinel.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count_sentinel.pass.cpp --- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count_sentinel.pass.cpp +++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count_sentinel.pass.cpp @@ -55,7 +55,7 @@ using Difference = std::iter_difference_t; auto current = stride_counting_iterator(It(range.begin())); Difference const result = std::ranges::advance(current, n, distance_apriori_sentinel(range.size())); - assert(current.base().base() == expected.coordinate); + assert(base(base(current)) == expected.coordinate); assert(result == expected.result); if constexpr (std::random_access_iterator) { @@ -72,7 +72,7 @@ using Difference = std::iter_difference_t; auto current = stride_counting_iterator(It(range.end())); Difference const result = std::ranges::advance(current, -n, stride_counting_iterator(It(range.begin()))); - assert(current.base().base() == expected.coordinate); + assert(base(base(current)) == expected.coordinate); assert(result == expected.result); assert(current.stride_count() == 0 || current.stride_count() == 1); @@ -84,7 +84,7 @@ using Difference = std::iter_difference_t; auto current = stride_counting_iterator(It(range.begin())); Difference const result = std::ranges::advance(current, n, sentinel_wrapper(It(range.end()))); - assert(current.base().base() == expected.coordinate); + assert(base(base(current)) == expected.coordinate); assert(result == expected.result); assert(current.stride_count() == n - result); } @@ -94,7 +94,7 @@ using Difference = std::iter_difference_t; auto current = stride_counting_iterator(It(range.end())); Difference const result = std::ranges::advance(current, -n, stride_counting_iterator(It(range.begin()))); - assert(current.base().base() == expected.coordinate); + assert(base(base(current)) == expected.coordinate); assert(result == expected.result); assert(current.stride_count() == n + result); assert(current.stride_count() == -current.stride_displacement()); diff --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_sentinel.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_sentinel.pass.cpp --- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_sentinel.pass.cpp +++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_sentinel.pass.cpp @@ -62,7 +62,7 @@ stride_counting_iterator first(It(range.begin())); stride_counting_iterator last(It(range.begin() + n)); std::ranges::advance(first, last); - assert(first.base().base() == range.begin() + n); + assert(base(base(first)) == range.begin() + n); assert(first.stride_count() == 0); // because we got here by assigning from last, not by incrementing } } @@ -86,7 +86,7 @@ distance_apriori_sentinel last(n); std::ranges::advance(first, last); - assert(first.base().base() == range.begin() + n); + assert(base(base(first)) == range.begin() + n); if constexpr (std::random_access_iterator) { assert(first.stride_count() == 1); assert(first.stride_displacement() == 1); @@ -115,7 +115,7 @@ stride_counting_iterator first(It(range.begin())); sentinel_wrapper last(It(range.begin() + n)); std::ranges::advance(first, last); - assert(first.base() == last); + assert(base(first) == last); assert(first.stride_count() == n); } } diff --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_sentinel.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_sentinel.pass.cpp --- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_sentinel.pass.cpp +++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_sentinel.pass.cpp @@ -71,7 +71,7 @@ auto strided_it = stride_counting_iterator(It(it)); auto strided_last = assignable_sentinel(stride_counting_iterator(It(last))); stride_counting_iterator result = std::ranges::next(std::move(strided_it), std::move(strided_last)); - assert(base(result.base()) == expected); + assert(base(base(result)) == expected); assert(result.stride_count() == 0); // because we got here by assigning from last, not by incrementing } } @@ -91,7 +91,7 @@ auto strided_it = stride_counting_iterator(It(it)); auto sent = distance_apriori_sentinel(n); auto result = std::ranges::next(std::move(strided_it), sent); - assert(base(result.base()) == expected); + assert(base(base(result)) == expected); if constexpr (std::random_access_iterator) { assert(result.stride_count() == 1); // should have used exactly one += @@ -118,7 +118,7 @@ auto strided_it = stride_counting_iterator(It(it)); auto sent = sentinel_wrapper(stride_counting_iterator(It(last))); stride_counting_iterator result = std::ranges::next(std::move(strided_it), sent); - assert(base(result.base()) == expected); + assert(base(base(result)) == expected); assert(result.stride_count() == n); // must have used ++ until it hit the sentinel } } diff --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count.pass.cpp --- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count.pass.cpp +++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count.pass.cpp @@ -20,7 +20,7 @@ template constexpr void check(It it, std::ptrdiff_t n, int const* expected) { stride_counting_iterator result = std::ranges::prev(stride_counting_iterator(std::move(it)), n); - assert(result.base().base() == expected); + assert(base(base(result)) == expected); if constexpr (std::random_access_iterator) { assert(result.stride_count() <= 1); diff --git a/libcxx/test/support/test_iterators.h b/libcxx/test/support/test_iterators.h --- a/libcxx/test/support/test_iterators.h +++ b/libcxx/test/support/test_iterators.h @@ -693,31 +693,29 @@ // * `stride_displacement`, which records the displacement of the calls. This means that both // op++/op+= will increase the displacement counter by 1, and op--/op-= will decrease the // displacement counter by 1. -template +template class stride_counting_iterator { public: - using value_type = typename iter_value_or_void::type; - using difference_type = std::iter_difference_t; - using iterator_concept = iterator_concept_t; + using value_type = typename iter_value_or_void::type; + using difference_type = std::iter_difference_t; + using iterator_concept = iterator_concept_t; stride_counting_iterator() = default; - constexpr explicit stride_counting_iterator(I current) : base_(std::move(current)) {} + constexpr explicit stride_counting_iterator(It const& it) : base_(base(it)) { } - constexpr const I& base() const& { return base_; } - - constexpr I base() && { return std::move(base_); } + friend constexpr It base(stride_counting_iterator const& it) { return It(it.base_); } constexpr difference_type stride_count() const { return stride_count_; } constexpr difference_type stride_displacement() const { return stride_displacement_; } - constexpr decltype(auto) operator*() const { return *base_; } + constexpr decltype(auto) operator*() const { return *It(base_); } - constexpr decltype(auto) operator[](difference_type const n) const { return base_[n]; } + constexpr decltype(auto) operator[](difference_type const n) const { return It(base_)[n]; } constexpr stride_counting_iterator& operator++() { - ++base_; + base_ = base(++It(base_)); ++stride_count_; ++stride_displacement_; return *this; @@ -726,7 +724,7 @@ constexpr void operator++(int) { ++*this; } constexpr stride_counting_iterator operator++(int) - requires std::forward_iterator + requires std::forward_iterator { auto temp = *this; ++*this; @@ -734,16 +732,16 @@ } constexpr stride_counting_iterator& operator--() - requires std::bidirectional_iterator + requires std::bidirectional_iterator { - --base_; + base_ = base(--It(base_)); ++stride_count_; --stride_displacement_; return *this; } constexpr stride_counting_iterator operator--(int) - requires std::bidirectional_iterator + requires std::bidirectional_iterator { auto temp = *this; --*this; @@ -751,79 +749,79 @@ } constexpr stride_counting_iterator& operator+=(difference_type const n) - requires std::random_access_iterator + requires std::random_access_iterator { - base_ += n; + base_ = base(It(base_) += n); ++stride_count_; ++stride_displacement_; return *this; } constexpr stride_counting_iterator& operator-=(difference_type const n) - requires std::random_access_iterator + requires std::random_access_iterator { - base_ -= n; + base_ = base(It(base_) -= n); ++stride_count_; --stride_displacement_; return *this; } - friend constexpr stride_counting_iterator operator+(stride_counting_iterator i, difference_type const n) - requires std::random_access_iterator + friend constexpr stride_counting_iterator operator+(stride_counting_iterator it, difference_type n) + requires std::random_access_iterator { - return i += n; + return it += n; } - friend constexpr stride_counting_iterator operator+(difference_type const n, stride_counting_iterator i) - requires std::random_access_iterator + friend constexpr stride_counting_iterator operator+(difference_type n, stride_counting_iterator it) + requires std::random_access_iterator { - return i += n; + return it += n; } - friend constexpr stride_counting_iterator operator-(stride_counting_iterator i, difference_type const n) - requires std::random_access_iterator + friend constexpr stride_counting_iterator operator-(stride_counting_iterator it, difference_type n) + requires std::random_access_iterator { - return i -= n; + return it -= n; } friend constexpr difference_type operator-(stride_counting_iterator const& x, stride_counting_iterator const& y) - requires std::sized_sentinel_for + requires std::sized_sentinel_for { - return x.base() - y.base(); + return base(x) - base(y); } constexpr bool operator==(stride_counting_iterator const& other) const - requires std::sentinel_for + requires std::sentinel_for { - return base_ == other.base_; + return It(base_) == It(other.base_); } - template S> - constexpr bool operator==(S const last) const + template Sent> + constexpr bool operator==(Sent last) const { - return base_ == last; + return It(base_) == last; } friend constexpr bool operator<(stride_counting_iterator const& x, stride_counting_iterator const& y) - requires std::random_access_iterator + requires std::random_access_iterator { - return x.base_ < y.base_; + return It(x.base_) < It(y.base_); } friend constexpr bool operator>(stride_counting_iterator const& x, stride_counting_iterator const& y) - requires std::random_access_iterator + requires std::random_access_iterator { return y < x; } friend constexpr bool operator<=(stride_counting_iterator const& x, stride_counting_iterator const& y) - requires std::random_access_iterator + requires std::random_access_iterator { return !(y < x); } friend constexpr bool operator>=(stride_counting_iterator const& x, stride_counting_iterator const& y) - requires std::random_access_iterator + requires std::random_access_iterator { return !(x < y); } @@ -832,7 +830,7 @@ void operator,(T const &) = delete; private: - I base_; + decltype(base(std::declval())) base_; difference_type stride_count_ = 0; difference_type stride_displacement_ = 0; };