diff --git a/libcxx/test/support/test_iterators.h b/libcxx/test/support/test_iterators.h index ef699642cb95..a6ca62833bfd 100644 --- a/libcxx/test/support/test_iterators.h +++ b/libcxx/test/support/test_iterators.h @@ -42,6 +42,8 @@ public: TEST_CONSTEXPR_CXX14 output_iterator operator++(int) {output_iterator tmp(*this); ++(*this); return tmp;} + friend TEST_CONSTEXPR It base(const output_iterator& i) { return i.it_; } + template void operator,(T const &) = delete; }; @@ -81,6 +83,8 @@ public: friend TEST_CONSTEXPR_CXX14 bool operator!=(const cpp17_input_iterator& x, const cpp17_input_iterator& y) {return !(x == y);} + friend TEST_CONSTEXPR It base(const cpp17_input_iterator& i) { return i.it_; } + template void operator,(T const &) = delete; }; @@ -129,6 +133,8 @@ public: friend TEST_CONSTEXPR_CXX14 bool operator!=(const forward_iterator& x, const forward_iterator& y) {return !(x == y);} + friend TEST_CONSTEXPR It base(const forward_iterator& i) { return i.it_; } + template void operator,(T const &) = delete; }; @@ -229,6 +235,8 @@ public: TEST_CONSTEXPR_CXX14 bidirectional_iterator operator--(int) {bidirectional_iterator tmp(*this); --(*this); return tmp;} + friend TEST_CONSTEXPR It base(const bidirectional_iterator& i) { return i.it_; } + template void operator,(T const &) = delete; }; @@ -289,6 +297,8 @@ public: TEST_CONSTEXPR_CXX14 reference operator[](difference_type n) const {return it_[n];} + friend TEST_CONSTEXPR It base(const random_access_iterator& i) { return i.it_; } + template void operator,(T const &) = delete; }; @@ -419,32 +429,14 @@ public: return x.base() != y.base(); } + friend TEST_CONSTEXPR It base(const contiguous_iterator& i) { return i.it_; } + template void operator,(T const &) = delete; }; #endif -template -TEST_CONSTEXPR_CXX14 Iter base(output_iterator i) { return i.base(); } - -template -TEST_CONSTEXPR_CXX14 Iter base(cpp17_input_iterator i) { return i.base(); } - -template -TEST_CONSTEXPR_CXX14 Iter base(forward_iterator i) { return i.base(); } - -template -TEST_CONSTEXPR_CXX14 Iter base(bidirectional_iterator i) { return i.base(); } - -template -TEST_CONSTEXPR_CXX14 Iter base(random_access_iterator i) { return i.base(); } - -#if TEST_STD_VER > 17 -template -TEST_CONSTEXPR_CXX14 Iter base(contiguous_iterator i) { return i.base(); } -#endif - -template // everything else +template // ADL base() for everything else (including pointers) TEST_CONSTEXPR_CXX14 Iter base(Iter i) { return i; } template @@ -628,42 +620,30 @@ private: #ifdef TEST_SUPPORTS_RANGES -template -struct cpp20_input_iterator { - using value_type = std::iter_value_t; - using difference_type = std::iter_difference_t; +template +class cpp20_input_iterator +{ + It it_; + +public: + using value_type = std::iter_value_t; + using difference_type = std::iter_difference_t; using iterator_concept = std::input_iterator_tag; - cpp20_input_iterator() = delete; - + constexpr explicit cpp20_input_iterator(It it) : it_(it) {} cpp20_input_iterator(cpp20_input_iterator&&) = default; cpp20_input_iterator& operator=(cpp20_input_iterator&&) = default; + constexpr decltype(auto) operator*() const { return *it_; } + constexpr cpp20_input_iterator& operator++() { ++it_; return *this; } + constexpr void operator++(int) { ++it_; } - cpp20_input_iterator(cpp20_input_iterator const&) = delete; - cpp20_input_iterator& operator=(cpp20_input_iterator const&) = delete; + constexpr const It& base() const& { return it_; } + constexpr It base() && { return std::move(it_); } - explicit constexpr cpp20_input_iterator(I base) : base_(std::move(base)) {} - - constexpr decltype(auto) operator*() const { return *base_; } - - constexpr cpp20_input_iterator& operator++() { - ++base_; - return *this; - } - - constexpr void operator++(int) { ++base_; } - - constexpr const I& base() const& { return base_; } - - constexpr I base() && { return std::move(base_); } - - friend constexpr I base(const cpp20_input_iterator& i) { return i.base_; } + friend constexpr It base(const cpp20_input_iterator& i) { return i.it_; } template void operator,(T const &) = delete; - -private: - I base_ = I(); }; template @@ -960,15 +940,15 @@ public: constexpr reference operator[](difference_type n) const {return it_[n];} - template - void operator,(T const &) = delete; - friend constexpr difference_type operator-(const three_way_contiguous_iterator& x, const three_way_contiguous_iterator& y) { return x.base() - y.base(); } friend auto operator<=>(const three_way_contiguous_iterator&, const three_way_contiguous_iterator&) = default; + + template + void operator,(T const &) = delete; }; #endif // TEST_STD_VER > 17 && defined(__cpp_lib_concepts)