diff --git a/libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op.const/convert.pass.cpp b/libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op.const/convert.pass.cpp --- a/libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op.const/convert.pass.cpp +++ b/libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op.const/convert.pass.cpp @@ -28,7 +28,7 @@ { const std::move_iterator r2(u); std::move_iterator r1 = r2; - assert(r1.base() == u); + assert(base(r1.base()) == base(u)); } struct Base {}; diff --git a/libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op=/move_iterator.pass.cpp b/libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op=/move_iterator.pass.cpp --- a/libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op=/move_iterator.pass.cpp +++ b/libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op=/move_iterator.pass.cpp @@ -30,7 +30,7 @@ const std::move_iterator r2(u); std::move_iterator r1(It(nullptr)); std::move_iterator& rr = (r1 = r2); - assert(r1.base() == u); + assert(base(r1.base()) == base(u)); assert(&rr == &r1); } diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/assign.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/assign.pass.cpp --- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/assign.pass.cpp +++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/assign.pass.cpp @@ -24,7 +24,7 @@ const std::reverse_iterator r2(u); std::reverse_iterator r1; std::reverse_iterator& rr = r1 = r2; - assert(r1.base() == u); + assert(base(r1.base()) == base(u)); assert(&rr == &r1); } diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/ctor.reverse_iterator.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/ctor.reverse_iterator.pass.cpp --- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/ctor.reverse_iterator.pass.cpp +++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/ctor.reverse_iterator.pass.cpp @@ -26,7 +26,7 @@ TEST_CONSTEXPR_CXX17 void test(U u) { const std::reverse_iterator r2(u); std::reverse_iterator r1 = r2; - assert(r1.base() == u); + assert(base(r1.base()) == base(u)); } TEST_CONSTEXPR_CXX17 bool tests() { diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/minus.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/minus.pass.cpp --- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/minus.pass.cpp +++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/minus.pass.cpp @@ -18,10 +18,14 @@ #include #include #include +#include #include "test_macros.h" #include "test_iterators.h" +template struct HasSubtract : std::false_type {}; +template struct HasSubtract : std::true_type {}; + template TEST_CONSTEXPR_CXX17 void test(It1 l, It2 r, std::ptrdiff_t x) { const std::reverse_iterator r1(l); @@ -30,13 +34,25 @@ } TEST_CONSTEXPR_CXX17 bool tests() { + using PC = const char*; char s[3] = {0}; - test(random_access_iterator(s), random_access_iterator(s), 0); - test(random_access_iterator(s), random_access_iterator(s+1), 1); - test(random_access_iterator(s+1), random_access_iterator(s), -1); + + // Test same base iterator type test(s, s, 0); test(s, s+1, 1); test(s+1, s, -1); + + // Test different (but subtractable) base iterator types + test(PC(s), s, 0); + test(PC(s), s+1, 1); + test(PC(s+1), s, -1); + + // Test non-subtractable base iterator types + static_assert( HasSubtract, std::reverse_iterator >::value, ""); + static_assert( HasSubtract, std::reverse_iterator >::value, ""); + static_assert(!HasSubtract, std::reverse_iterator >::value, ""); + static_assert(!HasSubtract >, std::reverse_iterator > >::value, ""); + return true; } diff --git a/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_long_double.pass.cpp b/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_long_double.pass.cpp --- a/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_long_double.pass.cpp +++ b/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_long_double.pass.cpp @@ -26221,7 +26221,6 @@ test10(); test11(); test12(); - output_iterator iter; std::locale lc = std::locale::classic(); std::locale lg(lc, new my_numpunct); const my_facet f(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 @@ -29,19 +29,17 @@ typedef It pointer; typedef typename std::iterator_traits::reference reference; - TEST_CONSTEXPR_CXX14 It base() const {return it_;} - - TEST_CONSTEXPR_CXX14 output_iterator() {} - explicit TEST_CONSTEXPR_CXX14 output_iterator(It it) : it_(it) {} + TEST_CONSTEXPR output_iterator() : it_() {} + TEST_CONSTEXPR explicit output_iterator(It it) : it_(std::move(it)) {} template - TEST_CONSTEXPR_CXX14 output_iterator(const output_iterator& u) :it_(u.it_) {} + TEST_CONSTEXPR output_iterator(const output_iterator& u) : it_(u.it_) {} - TEST_CONSTEXPR_CXX14 reference operator*() const {return *it_;} + TEST_CONSTEXPR reference operator*() const {return *it_;} TEST_CONSTEXPR_CXX14 output_iterator& operator++() {++it_; return *this;} - TEST_CONSTEXPR_CXX14 output_iterator operator++(int) - {output_iterator tmp(*this); ++(*this); return tmp;} + TEST_CONSTEXPR_CXX14 output_iterator operator++(int) {return output_iterator(it_++);} + TEST_CONSTEXPR It base() const {return it_;} // TODO remove me friend TEST_CONSTEXPR It base(const output_iterator& i) { return i.it_; } template @@ -64,42 +62,26 @@ typedef It pointer; typedef typename Traits::reference reference; - TEST_CONSTEXPR_CXX14 It base() const {return it_;} - - explicit TEST_CONSTEXPR_CXX14 cpp17_input_iterator(It it) : it_(it) {} + TEST_CONSTEXPR explicit cpp17_input_iterator(It it) : it_(it) {} template - TEST_CONSTEXPR_CXX14 cpp17_input_iterator(const cpp17_input_iterator& u) :it_(u.it_) {} + TEST_CONSTEXPR cpp17_input_iterator(const cpp17_input_iterator& u) : it_(u.it_) {} - TEST_CONSTEXPR_CXX14 reference operator*() const {return *it_;} - TEST_CONSTEXPR_CXX14 pointer operator->() const {return it_;} + TEST_CONSTEXPR reference operator*() const {return *it_;} + TEST_CONSTEXPR pointer operator->() const {return it_;} TEST_CONSTEXPR_CXX14 cpp17_input_iterator& operator++() {++it_; return *this;} - TEST_CONSTEXPR_CXX14 cpp17_input_iterator operator++(int) - {cpp17_input_iterator tmp(*this); ++(*this); return tmp;} + TEST_CONSTEXPR_CXX14 cpp17_input_iterator operator++(int) {return cpp17_input_iterator(it_++);} - friend TEST_CONSTEXPR_CXX14 bool operator==(const cpp17_input_iterator& x, const cpp17_input_iterator& y) - {return x.it_ == y.it_;} - friend TEST_CONSTEXPR_CXX14 bool operator!=(const cpp17_input_iterator& x, const cpp17_input_iterator& y) - {return !(x == y);} + friend TEST_CONSTEXPR bool operator==(const cpp17_input_iterator& x, const cpp17_input_iterator& y) {return x.it_ == y.it_;} + friend TEST_CONSTEXPR bool operator!=(const cpp17_input_iterator& x, const cpp17_input_iterator& y) {return x.it_ != y.it_;} + TEST_CONSTEXPR It base() const {return it_;} // TODO remove me friend TEST_CONSTEXPR It base(const cpp17_input_iterator& i) { return i.it_; } template void operator,(T const &) = delete; }; -template -bool operator==(const cpp17_input_iterator& x, const cpp17_input_iterator& y) -{ - return x.base() == y.base(); -} - -template -bool operator!=(const cpp17_input_iterator& x, const cpp17_input_iterator& y) -{ - return !(x == y); -} - template class forward_iterator { @@ -113,45 +95,27 @@ typedef It pointer; typedef typename std::iterator_traits::reference reference; - TEST_CONSTEXPR_CXX14 It base() const {return it_;} - - TEST_CONSTEXPR_CXX14 forward_iterator() : it_() {} - explicit TEST_CONSTEXPR_CXX14 forward_iterator(It it) : it_(it) {} + TEST_CONSTEXPR forward_iterator() : it_() {} + TEST_CONSTEXPR explicit forward_iterator(It it) : it_(it) {} template - TEST_CONSTEXPR_CXX14 forward_iterator(const forward_iterator& u) :it_(u.it_) {} + TEST_CONSTEXPR forward_iterator(const forward_iterator& u) : it_(u.it_) {} - TEST_CONSTEXPR_CXX14 reference operator*() const {return *it_;} - TEST_CONSTEXPR_CXX14 pointer operator->() const {return it_;} + TEST_CONSTEXPR reference operator*() const {return *it_;} + TEST_CONSTEXPR pointer operator->() const {return it_;} TEST_CONSTEXPR_CXX14 forward_iterator& operator++() {++it_; return *this;} - TEST_CONSTEXPR_CXX14 forward_iterator operator++(int) - {forward_iterator tmp(*this); ++(*this); return tmp;} + TEST_CONSTEXPR_CXX14 forward_iterator operator++(int) {return forward_iterator(it_++);} - friend TEST_CONSTEXPR_CXX14 bool operator==(const forward_iterator& x, const forward_iterator& y) - {return x.it_ == y.it_;} - friend TEST_CONSTEXPR_CXX14 bool operator!=(const forward_iterator& x, const forward_iterator& y) - {return !(x == y);} + friend TEST_CONSTEXPR bool operator==(const forward_iterator& x, const forward_iterator& y) {return x.it_ == y.it_;} + friend TEST_CONSTEXPR bool operator!=(const forward_iterator& x, const forward_iterator& y) {return x.it_ != y.it_;} + TEST_CONSTEXPR It base() const {return it_;} // TODO remove me friend TEST_CONSTEXPR It base(const forward_iterator& i) { return i.it_; } template void operator,(T const &) = delete; }; -template -TEST_CONSTEXPR_CXX14 -bool operator==(const forward_iterator& x, const forward_iterator& y) -{ - return x.base() == y.base(); -} - -template -TEST_CONSTEXPR_CXX14 -bool operator!=(const forward_iterator& x, const forward_iterator& y) -{ - return !(x == y); -} - template class non_default_constructible_iterator { @@ -165,44 +129,27 @@ typedef It pointer; typedef typename std::iterator_traits::reference reference; - TEST_CONSTEXPR_CXX14 It base() const {return it_;} + TEST_CONSTEXPR It base() const {return it_;} // TODO remove me non_default_constructible_iterator() = delete; - explicit TEST_CONSTEXPR_CXX14 non_default_constructible_iterator(It it) : it_(it) {} + TEST_CONSTEXPR explicit non_default_constructible_iterator(It it) : it_(it) {} template - TEST_CONSTEXPR_CXX14 non_default_constructible_iterator(const non_default_constructible_iterator& u) :it_(u.it_) {} + TEST_CONSTEXPR non_default_constructible_iterator(const non_default_constructible_iterator& u) : it_(u.it_) {} - TEST_CONSTEXPR_CXX14 reference operator*() const {return *it_;} - TEST_CONSTEXPR_CXX14 pointer operator->() const {return it_;} + TEST_CONSTEXPR reference operator*() const {return *it_;} + TEST_CONSTEXPR pointer operator->() const {return it_;} TEST_CONSTEXPR_CXX14 non_default_constructible_iterator& operator++() {++it_; return *this;} - TEST_CONSTEXPR_CXX14 non_default_constructible_iterator operator++(int) - {non_default_constructible_iterator tmp(*this); ++(*this); return tmp;} + TEST_CONSTEXPR_CXX14 non_default_constructible_iterator operator++(int) {return non_default_constructible_iterator(it_++);} - friend TEST_CONSTEXPR_CXX14 bool operator==(const non_default_constructible_iterator& x, const non_default_constructible_iterator& y) - {return x.it_ == y.it_;} - friend TEST_CONSTEXPR_CXX14 bool operator!=(const non_default_constructible_iterator& x, const non_default_constructible_iterator& y) - {return !(x == y);} + friend TEST_CONSTEXPR bool operator==(const non_default_constructible_iterator& x, const non_default_constructible_iterator& y) {return x.it_ == y.it_;} + friend TEST_CONSTEXPR bool operator!=(const non_default_constructible_iterator& x, const non_default_constructible_iterator& y) {return x.it_ != y.it_;} template void operator,(T const &) = delete; }; -template -TEST_CONSTEXPR_CXX14 -bool operator==(const non_default_constructible_iterator& x, const non_default_constructible_iterator& y) -{ - return x.base() == y.base(); -} - -template -TEST_CONSTEXPR_CXX14 -bool operator!=(const non_default_constructible_iterator& x, const non_default_constructible_iterator& y) -{ - return !(x == y); -} - template class bidirectional_iterator { @@ -216,44 +163,29 @@ typedef It pointer; typedef typename std::iterator_traits::reference reference; - TEST_CONSTEXPR_CXX14 It base() const {return it_;} - - TEST_CONSTEXPR_CXX14 bidirectional_iterator() : it_() {} - explicit TEST_CONSTEXPR_CXX14 bidirectional_iterator(It it) : it_(it) {} + TEST_CONSTEXPR bidirectional_iterator() : it_() {} + TEST_CONSTEXPR explicit bidirectional_iterator(It it) : it_(it) {} template - TEST_CONSTEXPR_CXX14 bidirectional_iterator(const bidirectional_iterator& u) :it_(u.it_) {} + TEST_CONSTEXPR bidirectional_iterator(const bidirectional_iterator& u) : it_(u.it_) {} - TEST_CONSTEXPR_CXX14 reference operator*() const {return *it_;} - TEST_CONSTEXPR_CXX14 pointer operator->() const {return it_;} + TEST_CONSTEXPR reference operator*() const {return *it_;} + TEST_CONSTEXPR pointer operator->() const {return it_;} TEST_CONSTEXPR_CXX14 bidirectional_iterator& operator++() {++it_; return *this;} - TEST_CONSTEXPR_CXX14 bidirectional_iterator operator++(int) - {bidirectional_iterator tmp(*this); ++(*this); return tmp;} - TEST_CONSTEXPR_CXX14 bidirectional_iterator& operator--() {--it_; return *this;} - TEST_CONSTEXPR_CXX14 bidirectional_iterator operator--(int) - {bidirectional_iterator tmp(*this); --(*this); return tmp;} + TEST_CONSTEXPR_CXX14 bidirectional_iterator operator++(int) {return bidirectional_iterator(it_++);} + TEST_CONSTEXPR_CXX14 bidirectional_iterator operator--(int) {return bidirectional_iterator(it_--);} + + friend TEST_CONSTEXPR bool operator==(const bidirectional_iterator& x, const bidirectional_iterator& y) {return x.it_ == y.it_;} + friend TEST_CONSTEXPR bool operator!=(const bidirectional_iterator& x, const bidirectional_iterator& y) {return x.it_ != y.it_;} + TEST_CONSTEXPR It base() const {return it_;} // TODO remove me friend TEST_CONSTEXPR It base(const bidirectional_iterator& i) { return i.it_; } template void operator,(T const &) = delete; }; -template -TEST_CONSTEXPR_CXX14 -bool operator==(const bidirectional_iterator& x, const bidirectional_iterator& y) -{ - return x.base() == y.base(); -} - -template -TEST_CONSTEXPR_CXX14 -bool operator!=(const bidirectional_iterator& x, const bidirectional_iterator& y) -{ - return !(x == y); -} - template class random_access_iterator { @@ -267,91 +199,41 @@ typedef It pointer; typedef typename std::iterator_traits::reference reference; - TEST_CONSTEXPR_CXX14 It base() const {return it_;} - - TEST_CONSTEXPR_CXX14 random_access_iterator() : it_() {} - explicit TEST_CONSTEXPR_CXX14 random_access_iterator(It it) : it_(it) {} + TEST_CONSTEXPR random_access_iterator() : it_() {} + TEST_CONSTEXPR explicit random_access_iterator(It it) : it_(it) {} template - TEST_CONSTEXPR_CXX14 random_access_iterator(const random_access_iterator& u) :it_(u.it_) {} + TEST_CONSTEXPR random_access_iterator(const random_access_iterator& u) : it_(u.it_) {} TEST_CONSTEXPR_CXX14 reference operator*() const {return *it_;} TEST_CONSTEXPR_CXX14 pointer operator->() const {return it_;} + TEST_CONSTEXPR_CXX14 reference operator[](difference_type n) const {return it_[n];} TEST_CONSTEXPR_CXX14 random_access_iterator& operator++() {++it_; return *this;} - TEST_CONSTEXPR_CXX14 random_access_iterator operator++(int) - {random_access_iterator tmp(*this); ++(*this); return tmp;} - TEST_CONSTEXPR_CXX14 random_access_iterator& operator--() {--it_; return *this;} - TEST_CONSTEXPR_CXX14 random_access_iterator operator--(int) - {random_access_iterator tmp(*this); --(*this); return tmp;} + TEST_CONSTEXPR_CXX14 random_access_iterator operator++(int) {return random_access_iterator(it_++);} + TEST_CONSTEXPR_CXX14 random_access_iterator operator--(int) {return random_access_iterator(it_--);} TEST_CONSTEXPR_CXX14 random_access_iterator& operator+=(difference_type n) {it_ += n; return *this;} - TEST_CONSTEXPR_CXX14 random_access_iterator operator+(difference_type n) const - {random_access_iterator tmp(*this); tmp += n; return tmp;} - friend TEST_CONSTEXPR_CXX14 random_access_iterator operator+(difference_type n, random_access_iterator x) - {x += n; return x;} - TEST_CONSTEXPR_CXX14 random_access_iterator& operator-=(difference_type n) {return *this += -n;} - TEST_CONSTEXPR_CXX14 random_access_iterator operator-(difference_type n) const - {random_access_iterator tmp(*this); tmp -= n; return tmp;} - - TEST_CONSTEXPR_CXX14 reference operator[](difference_type n) const {return it_[n];} - + TEST_CONSTEXPR_CXX14 random_access_iterator& operator-=(difference_type n) {it_ -= n; return *this;} + friend TEST_CONSTEXPR_CXX14 random_access_iterator operator+(random_access_iterator x, difference_type n) {x += n; return x;} + friend TEST_CONSTEXPR_CXX14 random_access_iterator operator+(difference_type n, random_access_iterator x) {x += n; return x;} + friend TEST_CONSTEXPR_CXX14 random_access_iterator operator-(random_access_iterator x, difference_type n) {x -= n; return x;} + friend TEST_CONSTEXPR difference_type operator-(random_access_iterator x, random_access_iterator y) {return x.it_ - y.it_;} + + friend TEST_CONSTEXPR bool operator==(const random_access_iterator& x, const random_access_iterator& y) {return x.it_ == y.it_;} + friend TEST_CONSTEXPR bool operator!=(const random_access_iterator& x, const random_access_iterator& y) {return x.it_ != y.it_;} + friend TEST_CONSTEXPR bool operator< (const random_access_iterator& x, const random_access_iterator& y) {return x.it_ < y.it_;} + friend TEST_CONSTEXPR bool operator<=(const random_access_iterator& x, const random_access_iterator& y) {return x.it_ <= y.it_;} + friend TEST_CONSTEXPR bool operator> (const random_access_iterator& x, const random_access_iterator& y) {return x.it_ > y.it_;} + friend TEST_CONSTEXPR bool operator>=(const random_access_iterator& x, const random_access_iterator& y) {return x.it_ >= y.it_;} + + TEST_CONSTEXPR It base() const {return it_;} // TODO remove me friend TEST_CONSTEXPR It base(const random_access_iterator& i) { return i.it_; } template void operator,(T const &) = delete; }; -template -TEST_CONSTEXPR_CXX14 -bool operator==(const random_access_iterator& x, const random_access_iterator& y) -{ - return x.base() == y.base(); -} - -template -TEST_CONSTEXPR_CXX14 -bool operator!=(const random_access_iterator& x, const random_access_iterator& y) -{ - return !(x == y); -} - -template -TEST_CONSTEXPR_CXX14 -bool operator<(const random_access_iterator& x, const random_access_iterator& y) -{ - return x.base() < y.base(); -} - -template -TEST_CONSTEXPR_CXX14 -bool operator<=(const random_access_iterator& x, const random_access_iterator& y) -{ - return !(y < x); -} - -template -TEST_CONSTEXPR_CXX14 -bool operator>(const random_access_iterator& x, const random_access_iterator& y) -{ - return y < x; -} - -template -TEST_CONSTEXPR_CXX14 -bool operator>=(const random_access_iterator& x, const random_access_iterator& y) -{ - return !(x < y); -} - -template -TEST_CONSTEXPR_CXX14 -typename std::iterator_traits::difference_type -operator-(const random_access_iterator& x, const random_access_iterator& y) -{ - return x.base() - y.base(); -} - #if TEST_STD_VER > 17 template class contiguous_iterator @@ -372,71 +254,88 @@ TEST_CONSTEXPR_CXX14 It base() const {return it_;} TEST_CONSTEXPR_CXX14 contiguous_iterator() : it_() {} - explicit TEST_CONSTEXPR_CXX14 contiguous_iterator(It it) : it_(it) {} + TEST_CONSTEXPR_CXX14 explicit contiguous_iterator(It it) : it_(it) {} template TEST_CONSTEXPR_CXX14 contiguous_iterator(const contiguous_iterator& u) : it_(u.it_) {} - TEST_CONSTEXPR_CXX14 reference operator*() const {return *it_;} - TEST_CONSTEXPR_CXX14 pointer operator->() const {return it_;} + TEST_CONSTEXPR reference operator*() const {return *it_;} + TEST_CONSTEXPR pointer operator->() const {return it_;} + TEST_CONSTEXPR reference operator[](difference_type n) const {return it_[n];} TEST_CONSTEXPR_CXX14 contiguous_iterator& operator++() {++it_; return *this;} - TEST_CONSTEXPR_CXX14 contiguous_iterator operator++(int) - {contiguous_iterator tmp(*this); ++(*this); return tmp;} - TEST_CONSTEXPR_CXX14 contiguous_iterator& operator--() {--it_; return *this;} - TEST_CONSTEXPR_CXX14 contiguous_iterator operator--(int) - {contiguous_iterator tmp(*this); --(*this); return tmp;} + TEST_CONSTEXPR_CXX14 contiguous_iterator operator++(int) {return contiguous_iterator(it_++);} + TEST_CONSTEXPR_CXX14 contiguous_iterator operator--(int) {return contiguous_iterator(it_--);} TEST_CONSTEXPR_CXX14 contiguous_iterator& operator+=(difference_type n) {it_ += n; return *this;} - TEST_CONSTEXPR_CXX14 contiguous_iterator operator+(difference_type n) const - {contiguous_iterator tmp(*this); tmp += n; return tmp;} - friend TEST_CONSTEXPR_CXX14 contiguous_iterator operator+(difference_type n, contiguous_iterator x) - {x += n; return x;} - TEST_CONSTEXPR_CXX14 contiguous_iterator& operator-=(difference_type n) {return *this += -n;} - TEST_CONSTEXPR_CXX14 contiguous_iterator operator-(difference_type n) const - {contiguous_iterator tmp(*this); tmp -= n; return tmp;} + TEST_CONSTEXPR_CXX14 contiguous_iterator& operator-=(difference_type n) {it_ -= n; return *this;} + friend TEST_CONSTEXPR_CXX14 contiguous_iterator operator+(contiguous_iterator x, difference_type n) {x += n; return x;} + friend TEST_CONSTEXPR_CXX14 contiguous_iterator operator+(difference_type n, contiguous_iterator x) {x += n; return x;} + friend TEST_CONSTEXPR_CXX14 contiguous_iterator operator-(contiguous_iterator x, difference_type n) {x -= n; return x;} + friend TEST_CONSTEXPR difference_type operator-(contiguous_iterator x, contiguous_iterator y) {return x.it_ - y.it_;} + + friend TEST_CONSTEXPR bool operator==(const contiguous_iterator& x, const contiguous_iterator& y) {return x.it_ == y.it_;} + friend TEST_CONSTEXPR bool operator!=(const contiguous_iterator& x, const contiguous_iterator& y) {return x.it_ != y.it_;} + friend TEST_CONSTEXPR bool operator< (const contiguous_iterator& x, const contiguous_iterator& y) {return x.it_ < y.it_;} + friend TEST_CONSTEXPR bool operator<=(const contiguous_iterator& x, const contiguous_iterator& y) {return x.it_ <= y.it_;} + friend TEST_CONSTEXPR bool operator> (const contiguous_iterator& x, const contiguous_iterator& y) {return x.it_ > y.it_;} + friend TEST_CONSTEXPR bool operator>=(const contiguous_iterator& x, const contiguous_iterator& y) {return x.it_ >= y.it_;} - TEST_CONSTEXPR_CXX14 reference operator[](difference_type n) const {return it_[n];} + friend TEST_CONSTEXPR It base(const contiguous_iterator& i) { return i.it_; } - friend TEST_CONSTEXPR_CXX14 - difference_type operator-(const contiguous_iterator& x, const contiguous_iterator& y) { - return x.base() - y.base(); - } + template + void operator,(T const &) = delete; +}; - friend TEST_CONSTEXPR_CXX14 - difference_type operator<(const contiguous_iterator& x, const contiguous_iterator& y) { - return x.base() < y.base(); - } - friend TEST_CONSTEXPR_CXX14 - difference_type operator>(const contiguous_iterator& x, const contiguous_iterator& y) { - return x.base() > y.base(); - } - friend TEST_CONSTEXPR_CXX14 - difference_type operator<=(const contiguous_iterator& x, const contiguous_iterator& y) { - return x.base() <= y.base(); - } - friend TEST_CONSTEXPR_CXX14 - difference_type operator>=(const contiguous_iterator& x, const contiguous_iterator& y) { - return x.base() >= y.base(); - } - friend TEST_CONSTEXPR_CXX14 - difference_type operator==(const contiguous_iterator& x, const contiguous_iterator& y) { - return x.base() == y.base(); - } - friend TEST_CONSTEXPR_CXX14 - difference_type operator!=(const contiguous_iterator& x, const contiguous_iterator& y) { - return x.base() != y.base(); - } +template +class three_way_contiguous_iterator +{ + static_assert(std::is_pointer_v, "Things probably break in this case"); - friend TEST_CONSTEXPR It base(const contiguous_iterator& i) { return i.it_; } + It it_; + + template friend class three_way_contiguous_iterator; +public: + typedef std::contiguous_iterator_tag iterator_category; + typedef typename std::iterator_traits::value_type value_type; + typedef typename std::iterator_traits::difference_type difference_type; + typedef It pointer; + typedef typename std::iterator_traits::reference reference; + typedef typename std::remove_pointer::type element_type; + + constexpr It base() const {return it_;} + + constexpr three_way_contiguous_iterator() : it_() {} + constexpr explicit three_way_contiguous_iterator(It it) : it_(it) {} + template + constexpr three_way_contiguous_iterator(const three_way_contiguous_iterator& u) : it_(u.it_) {} + + constexpr reference operator*() const {return *it_;} + constexpr pointer operator->() const {return it_;} + constexpr reference operator[](difference_type n) const {return it_[n];} + + constexpr three_way_contiguous_iterator& operator++() {++it_; return *this;} + constexpr three_way_contiguous_iterator& operator--() {--it_; return *this;} + constexpr three_way_contiguous_iterator operator++(int) {return three_way_contiguous_iterator(it_++);} + constexpr three_way_contiguous_iterator operator--(int) {return three_way_contiguous_iterator(it_--);} + + constexpr three_way_contiguous_iterator& operator+=(difference_type n) {it_ += n; return *this;} + constexpr three_way_contiguous_iterator& operator-=(difference_type n) {it_ -= n; return *this;} + friend constexpr three_way_contiguous_iterator operator+(three_way_contiguous_iterator x, difference_type n) {x += n; return x;} + friend constexpr three_way_contiguous_iterator operator+(difference_type n, three_way_contiguous_iterator x) {x += n; return x;} + friend constexpr three_way_contiguous_iterator operator-(three_way_contiguous_iterator x, difference_type n) {x -= n; return x;} + friend constexpr difference_type operator-(three_way_contiguous_iterator x, three_way_contiguous_iterator y) {return x.it_ - y.it_;} + + friend constexpr auto operator<=>(const three_way_contiguous_iterator& x, const three_way_contiguous_iterator& y) {return x.it_ <=> y.it_;} + friend constexpr bool operator==(const three_way_contiguous_iterator& x, const three_way_contiguous_iterator& y) {return x.it_ == y.it_;} template void operator,(T const &) = delete; }; -#endif +#endif // TEST_STD_VER > 17 template // ADL base() for everything else (including pointers) -TEST_CONSTEXPR_CXX14 Iter base(Iter i) { return i; } +TEST_CONSTEXPR Iter base(Iter i) { return i; } template struct ThrowingIterator { @@ -619,7 +518,6 @@ }; #ifdef TEST_SUPPORTS_RANGES - template class cpp20_input_iterator { @@ -637,9 +535,7 @@ constexpr cpp20_input_iterator& operator++() { ++it_; return *this; } constexpr void operator++(int) { ++it_; } - constexpr const It& base() const& { return it_; } - constexpr It base() && { return std::move(it_); } - + constexpr const It& base() const& { return it_; } // TODO remove me friend constexpr It base(const cpp20_input_iterator& i) { return i.it_; } template @@ -836,7 +732,9 @@ difference_type stride_count_ = 0; difference_type stride_displacement_ = 0; }; +#endif // TEST_SUPPORTS_RANGES +#if TEST_STD_VER > 17 template class sentinel_wrapper { public: @@ -860,58 +758,6 @@ private: decltype(base(std::declval())) base_; }; - -template -class three_way_contiguous_iterator -{ - static_assert(std::is_pointer_v, "Things probably break in this case"); - - It it_; - - template friend class three_way_contiguous_iterator; -public: - typedef std::contiguous_iterator_tag iterator_category; - typedef typename std::iterator_traits::value_type value_type; - typedef typename std::iterator_traits::difference_type difference_type; - typedef It pointer; - typedef typename std::iterator_traits::reference reference; - typedef typename std::remove_pointer::type element_type; - - constexpr It base() const {return it_;} - - constexpr three_way_contiguous_iterator() : it_() {} - constexpr explicit three_way_contiguous_iterator(It it) : it_(it) {} - template - constexpr three_way_contiguous_iterator(const three_way_contiguous_iterator& u) : it_(u.it_) {} - - constexpr reference operator*() const {return *it_;} - constexpr pointer operator->() const {return it_;} - - constexpr three_way_contiguous_iterator& operator++() {++it_; return *this;} - constexpr three_way_contiguous_iterator operator++(int) {auto tmp = *this; ++(*this); return tmp;} - - constexpr three_way_contiguous_iterator& operator--() {--it_; return *this;} - constexpr three_way_contiguous_iterator operator--(int) {auto tmp = *this; --(*this); return tmp;} - - constexpr three_way_contiguous_iterator& operator+=(difference_type n) {it_ += n; return *this;} - constexpr auto operator+(difference_type n) const {auto tmp = *this; tmp += n; return tmp;} - friend constexpr auto operator+(difference_type n, three_way_contiguous_iterator x) {x += n; return x;} - constexpr three_way_contiguous_iterator& operator-=(difference_type n) {return *this += -n;} - constexpr auto operator-(difference_type n) const {auto tmp = *this; tmp -= n; return tmp;} - - constexpr reference operator[](difference_type n) const {return it_[n];} - - 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) +#endif // TEST_STD_VER > 17 #endif // SUPPORT_TEST_ITERATORS_H