[libcxx-commits] [libcxx] 3049d51 - [libc++] [test] Use hidden friends consistently in the test iterators.
Arthur O'Dwyer via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jan 18 10:05:03 PST 2022
Author: Arthur O'Dwyer
Date: 2022-01-18T13:04:40-05:00
New Revision: 3049d51e9858ccb645c7faf430ae48b04d3a8076
URL: https://github.com/llvm/llvm-project/commit/3049d51e9858ccb645c7faf430ae48b04d3a8076
DIFF: https://github.com/llvm/llvm-project/commit/3049d51e9858ccb645c7faf430ae48b04d3a8076.diff
LOG: [libc++] [test] Use hidden friends consistently in the test iterators.
Differential Revision: https://reviews.llvm.org/D117397
Added:
Modified:
libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op.const/convert.pass.cpp
libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op=/move_iterator.pass.cpp
libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/assign.pass.cpp
libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/ctor.reverse_iterator.pass.cpp
libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/minus.pass.cpp
libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_long_double.pass.cpp
libcxx/test/support/test_iterators.h
Removed:
################################################################################
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
index 189dee3b1d740..460aaadba8767 100644
--- 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 @@ test(U u)
{
const std::move_iterator<U> r2(u);
std::move_iterator<It> 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
index a55d7a345074d..42a28cf14cfd0 100644
--- 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 @@ test(U u)
const std::move_iterator<U> r2(u);
std::move_iterator<It> r1(It(nullptr));
std::move_iterator<It>& 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
index be7f01c16810f..c3dbfa9a41b66 100644
--- 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 @@ TEST_CONSTEXPR_CXX17 void test(U u) {
const std::reverse_iterator<U> r2(u);
std::reverse_iterator<It> r1;
std::reverse_iterator<It>& 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
index 9aa6995e0ebba..8f315e83f6d7b 100644
--- 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 @@ template <class It, class U>
TEST_CONSTEXPR_CXX17 void test(U u) {
const std::reverse_iterator<U> r2(u);
std::reverse_iterator<It> 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
index 889eb8c66c3ba..f7f74d145d73c 100644
--- 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 <iterator>
#include <cstddef>
#include <cassert>
+#include <type_traits>
#include "test_macros.h"
#include "test_iterators.h"
+template <class, class, class = void> struct HasMinus : std::false_type {};
+template <class R1, class R2> struct HasMinus<R1, R2, decltype((R1() - R2(), void()))> : std::true_type {};
+
template <class It1, class It2>
TEST_CONSTEXPR_CXX17 void test(It1 l, It2 r, std::ptr
diff _t x) {
const std::reverse_iterator<It1> r1(l);
@@ -30,13 +34,27 @@ TEST_CONSTEXPR_CXX17 void test(It1 l, It2 r, std::ptr
diff _t x) {
}
TEST_CONSTEXPR_CXX17 bool tests() {
+ using PC = const char*;
char s[3] = {0};
- test(random_access_iterator<const char*>(s), random_access_iterator<char*>(s), 0);
- test(random_access_iterator<char*>(s), random_access_iterator<const char*>(s+1), 1);
- test(random_access_iterator<const char*>(s+1), random_access_iterator<char*>(s), -1);
+
+ // Test same base iterator type
test(s, s, 0);
test(s, s+1, 1);
test(s+1, s, -1);
+
+ // Test
diff erent (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( HasMinus<std::reverse_iterator<int*>, std::reverse_iterator<int*> >::value, "");
+ static_assert( HasMinus<std::reverse_iterator<int*>, std::reverse_iterator<const int*> >::value, "");
+#if TEST_STD_VER >= 11
+ static_assert(!HasMinus<std::reverse_iterator<int*>, std::reverse_iterator<char*> >::value, "");
+ static_assert(!HasMinus<std::reverse_iterator<bidirectional_iterator<int*> >, std::reverse_iterator<bidirectional_iterator<int*> > >::value, "");
+#endif
+
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
index 858a7df11b968..e63f5762b1d80 100644
--- 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
@@ -24415,12 +24415,12 @@ void test11()
void test12()
{
- output_iterator<char*> iter;
std::locale lc = std::locale::classic();
std::locale lg(lc, new my_numpunct);
#if defined(__APPLE__) && defined(__x86_64__)
// This test is failing on FreeBSD, possibly due to
diff erent representations
// of the floating point numbers.
+ output_iterator<char*> iter;
const my_facet f(1);
char str[200];
{
@@ -26221,7 +26221,6 @@ int main(int, char**)
test10();
test11();
test12();
- output_iterator<char*> 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
index 8bd187df15e67..5e084d3222c68 100644
--- a/libcxx/test/support/test_iterators.h
+++ b/libcxx/test/support/test_iterators.h
@@ -30,19 +30,17 @@ class output_iterator
typedef It pointer;
typedef typename std::iterator_traits<It>::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 <class U>
- TEST_CONSTEXPR_CXX14 output_iterator(const output_iterator<U>& u) :it_(u.it_) {}
+ TEST_CONSTEXPR output_iterator(const output_iterator<U>& 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 <class T>
@@ -65,42 +63,26 @@ class cpp17_input_iterator
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 <class U, class T>
- TEST_CONSTEXPR_CXX14 cpp17_input_iterator(const cpp17_input_iterator<U, T>& u) :it_(u.it_) {}
+ TEST_CONSTEXPR cpp17_input_iterator(const cpp17_input_iterator<U, T>& 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 <class T>
void operator,(T const &) = delete;
};
-template <class T, class TV, class U, class UV>
-bool operator==(const cpp17_input_iterator<T, TV>& x, const cpp17_input_iterator<U, UV>& y)
-{
- return x.base() == y.base();
-}
-
-template <class T, class TV, class U, class UV>
-bool operator!=(const cpp17_input_iterator<T, TV>& x, const cpp17_input_iterator<U, UV>& y)
-{
- return !(x == y);
-}
-
template <class It>
class forward_iterator
{
@@ -114,45 +96,27 @@ class forward_iterator
typedef It pointer;
typedef typename std::iterator_traits<It>::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 <class U>
- TEST_CONSTEXPR_CXX14 forward_iterator(const forward_iterator<U>& u) :it_(u.it_) {}
+ TEST_CONSTEXPR forward_iterator(const forward_iterator<U>& 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 <class T>
void operator,(T const &) = delete;
};
-template <class T, class U>
-TEST_CONSTEXPR_CXX14
-bool operator==(const forward_iterator<T>& x, const forward_iterator<U>& y)
-{
- return x.base() == y.base();
-}
-
-template <class T, class U>
-TEST_CONSTEXPR_CXX14
-bool operator!=(const forward_iterator<T>& x, const forward_iterator<U>& y)
-{
- return !(x == y);
-}
-
template <class It>
class non_default_constructible_iterator
{
@@ -166,44 +130,25 @@ class non_default_constructible_iterator
typedef It pointer;
typedef typename std::iterator_traits<It>::reference reference;
- TEST_CONSTEXPR_CXX14 It base() const {return it_;}
-
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 <class U>
- TEST_CONSTEXPR_CXX14 non_default_constructible_iterator(const non_default_constructible_iterator<U>& u) :it_(u.it_) {}
+ TEST_CONSTEXPR non_default_constructible_iterator(const non_default_constructible_iterator<U>& 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 <class T>
void operator,(T const &) = delete;
};
-template <class T, class U>
-TEST_CONSTEXPR_CXX14
-bool operator==(const non_default_constructible_iterator<T>& x, const non_default_constructible_iterator<U>& y)
-{
- return x.base() == y.base();
-}
-
-template <class T, class U>
-TEST_CONSTEXPR_CXX14
-bool operator!=(const non_default_constructible_iterator<T>& x, const non_default_constructible_iterator<U>& y)
-{
- return !(x == y);
-}
-
template <class It>
class bidirectional_iterator
{
@@ -217,44 +162,29 @@ class bidirectional_iterator
typedef It pointer;
typedef typename std::iterator_traits<It>::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 <class U>
- TEST_CONSTEXPR_CXX14 bidirectional_iterator(const bidirectional_iterator<U>& u) :it_(u.it_) {}
+ TEST_CONSTEXPR bidirectional_iterator(const bidirectional_iterator<U>& 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 <class T>
void operator,(T const &) = delete;
};
-template <class T, class U>
-TEST_CONSTEXPR_CXX14
-bool operator==(const bidirectional_iterator<T>& x, const bidirectional_iterator<U>& y)
-{
- return x.base() == y.base();
-}
-
-template <class T, class U>
-TEST_CONSTEXPR_CXX14
-bool operator!=(const bidirectional_iterator<T>& x, const bidirectional_iterator<U>& y)
-{
- return !(x == y);
-}
-
template <class It>
class random_access_iterator
{
@@ -268,91 +198,41 @@ class random_access_iterator
typedef It pointer;
typedef typename std::iterator_traits<It>::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 <class U>
- TEST_CONSTEXPR_CXX14 random_access_iterator(const random_access_iterator<U>& u) :it_(u.it_) {}
+ TEST_CONSTEXPR random_access_iterator(const random_access_iterator<U>& 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[](
diff erence_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+=(
diff erence_type n) {it_ += n; return *this;}
- TEST_CONSTEXPR_CXX14 random_access_iterator operator+(
diff erence_type n) const
- {random_access_iterator tmp(*this); tmp += n; return tmp;}
- friend TEST_CONSTEXPR_CXX14 random_access_iterator operator+(
diff erence_type n, random_access_iterator x)
- {x += n; return x;}
- TEST_CONSTEXPR_CXX14 random_access_iterator& operator-=(
diff erence_type n) {return *this += -n;}
- TEST_CONSTEXPR_CXX14 random_access_iterator operator-(
diff erence_type n) const
- {random_access_iterator tmp(*this); tmp -= n; return tmp;}
-
- TEST_CONSTEXPR_CXX14 reference operator[](
diff erence_type n) const {return it_[n];}
-
+ TEST_CONSTEXPR_CXX14 random_access_iterator& operator-=(
diff erence_type n) {it_ -= n; return *this;}
+ friend TEST_CONSTEXPR_CXX14 random_access_iterator operator+(random_access_iterator x,
diff erence_type n) {x += n; return x;}
+ friend TEST_CONSTEXPR_CXX14 random_access_iterator operator+(
diff erence_type n, random_access_iterator x) {x += n; return x;}
+ friend TEST_CONSTEXPR_CXX14 random_access_iterator operator-(random_access_iterator x,
diff erence_type n) {x -= n; return x;}
+ friend TEST_CONSTEXPR
diff erence_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 <class T>
void operator,(T const &) = delete;
};
-template <class T, class U>
-TEST_CONSTEXPR_CXX14
-bool operator==(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
-{
- return x.base() == y.base();
-}
-
-template <class T, class U>
-TEST_CONSTEXPR_CXX14
-bool operator!=(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
-{
- return !(x == y);
-}
-
-template <class T, class U>
-TEST_CONSTEXPR_CXX14
-bool operator<(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
-{
- return x.base() < y.base();
-}
-
-template <class T, class U>
-TEST_CONSTEXPR_CXX14
-bool operator<=(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
-{
- return !(y < x);
-}
-
-template <class T, class U>
-TEST_CONSTEXPR_CXX14
-bool operator>(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
-{
- return y < x;
-}
-
-template <class T, class U>
-TEST_CONSTEXPR_CXX14
-bool operator>=(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
-{
- return !(x < y);
-}
-
-template <class T, class U>
-TEST_CONSTEXPR_CXX14
-typename std::iterator_traits<T>::
diff erence_type
-operator-(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
-{
- return x.base() - y.base();
-}
-
#if TEST_STD_VER > 17
template <class It>
class contiguous_iterator
@@ -373,71 +253,88 @@ class contiguous_iterator
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 <class U>
TEST_CONSTEXPR_CXX14 contiguous_iterator(const contiguous_iterator<U>& 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[](
diff erence_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+=(
diff erence_type n) {it_ += n; return *this;}
- TEST_CONSTEXPR_CXX14 contiguous_iterator operator+(
diff erence_type n) const
- {contiguous_iterator tmp(*this); tmp += n; return tmp;}
- friend TEST_CONSTEXPR_CXX14 contiguous_iterator operator+(
diff erence_type n, contiguous_iterator x)
- {x += n; return x;}
- TEST_CONSTEXPR_CXX14 contiguous_iterator& operator-=(
diff erence_type n) {return *this += -n;}
- TEST_CONSTEXPR_CXX14 contiguous_iterator operator-(
diff erence_type n) const
- {contiguous_iterator tmp(*this); tmp -= n; return tmp;}
+ TEST_CONSTEXPR_CXX14 contiguous_iterator& operator-=(
diff erence_type n) {it_ -= n; return *this;}
+ friend TEST_CONSTEXPR_CXX14 contiguous_iterator operator+(contiguous_iterator x,
diff erence_type n) {x += n; return x;}
+ friend TEST_CONSTEXPR_CXX14 contiguous_iterator operator+(
diff erence_type n, contiguous_iterator x) {x += n; return x;}
+ friend TEST_CONSTEXPR_CXX14 contiguous_iterator operator-(contiguous_iterator x,
diff erence_type n) {x -= n; return x;}
+ friend TEST_CONSTEXPR
diff erence_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[](
diff erence_type n) const {return it_[n];}
+ friend TEST_CONSTEXPR It base(const contiguous_iterator& i) { return i.it_; }
- friend TEST_CONSTEXPR_CXX14
-
diff erence_type operator-(const contiguous_iterator& x, const contiguous_iterator& y) {
- return x.base() - y.base();
- }
+ template <class T>
+ void operator,(T const &) = delete;
+};
- friend TEST_CONSTEXPR_CXX14
-
diff erence_type operator<(const contiguous_iterator& x, const contiguous_iterator& y) {
- return x.base() < y.base();
- }
- friend TEST_CONSTEXPR_CXX14
-
diff erence_type operator>(const contiguous_iterator& x, const contiguous_iterator& y) {
- return x.base() > y.base();
- }
- friend TEST_CONSTEXPR_CXX14
-
diff erence_type operator<=(const contiguous_iterator& x, const contiguous_iterator& y) {
- return x.base() <= y.base();
- }
- friend TEST_CONSTEXPR_CXX14
-
diff erence_type operator>=(const contiguous_iterator& x, const contiguous_iterator& y) {
- return x.base() >= y.base();
- }
- friend TEST_CONSTEXPR_CXX14
-
diff erence_type operator==(const contiguous_iterator& x, const contiguous_iterator& y) {
- return x.base() == y.base();
- }
- friend TEST_CONSTEXPR_CXX14
-
diff erence_type operator!=(const contiguous_iterator& x, const contiguous_iterator& y) {
- return x.base() != y.base();
- }
+template <class It>
+class three_way_contiguous_iterator
+{
+ static_assert(std::is_pointer_v<It>, "Things probably break in this case");
- friend TEST_CONSTEXPR It base(const contiguous_iterator& i) { return i.it_; }
+ It it_;
+
+ template <class U> friend class three_way_contiguous_iterator;
+public:
+ typedef std::contiguous_iterator_tag iterator_category;
+ typedef typename std::iterator_traits<It>::value_type value_type;
+ typedef typename std::iterator_traits<It>::
diff erence_type
diff erence_type;
+ typedef It pointer;
+ typedef typename std::iterator_traits<It>::reference reference;
+ typedef typename std::remove_pointer<It>::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 <class U>
+ constexpr three_way_contiguous_iterator(const three_way_contiguous_iterator<U>& u) : it_(u.it_) {}
+
+ constexpr reference operator*() const {return *it_;}
+ constexpr pointer operator->() const {return it_;}
+ constexpr reference operator[](
diff erence_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+=(
diff erence_type n) {it_ += n; return *this;}
+ constexpr three_way_contiguous_iterator& operator-=(
diff erence_type n) {it_ -= n; return *this;}
+ friend constexpr three_way_contiguous_iterator operator+(three_way_contiguous_iterator x,
diff erence_type n) {x += n; return x;}
+ friend constexpr three_way_contiguous_iterator operator+(
diff erence_type n, three_way_contiguous_iterator x) {x += n; return x;}
+ friend constexpr three_way_contiguous_iterator operator-(three_way_contiguous_iterator x,
diff erence_type n) {x -= n; return x;}
+ friend constexpr
diff erence_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 <class T>
void operator,(T const &) = delete;
};
-#endif
+#endif // TEST_STD_VER > 17
template <class Iter> // 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 <typename T>
struct ThrowingIterator {
@@ -620,7 +517,6 @@ struct NonThrowingIterator {
};
#ifdef TEST_SUPPORTS_RANGES
-
template <class It>
class cpp20_input_iterator
{
@@ -638,9 +534,7 @@ class cpp20_input_iterator
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 <class T>
@@ -807,7 +701,9 @@ class stride_counting_iterator {
diff erence_type stride_count_ = 0;
diff erence_type stride_displacement_ = 0;
};
+#endif // TEST_SUPPORTS_RANGES
+#if TEST_STD_VER > 17
template <class It>
class sentinel_wrapper {
public:
@@ -831,58 +727,6 @@ class sized_sentinel {
private:
decltype(base(std::declval<It>())) base_;
};
-
-template <class It>
-class three_way_contiguous_iterator
-{
- static_assert(std::is_pointer_v<It>, "Things probably break in this case");
-
- It it_;
-
- template <class U> friend class three_way_contiguous_iterator;
-public:
- typedef std::contiguous_iterator_tag iterator_category;
- typedef typename std::iterator_traits<It>::value_type value_type;
- typedef typename std::iterator_traits<It>::
diff erence_type
diff erence_type;
- typedef It pointer;
- typedef typename std::iterator_traits<It>::reference reference;
- typedef typename std::remove_pointer<It>::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 <class U>
- constexpr three_way_contiguous_iterator(const three_way_contiguous_iterator<U>& 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+=(
diff erence_type n) {it_ += n; return *this;}
- constexpr auto operator+(
diff erence_type n) const {auto tmp = *this; tmp += n; return tmp;}
- friend constexpr auto operator+(
diff erence_type n, three_way_contiguous_iterator x) {x += n; return x;}
- constexpr three_way_contiguous_iterator& operator-=(
diff erence_type n) {return *this += -n;}
- constexpr auto operator-(
diff erence_type n) const {auto tmp = *this; tmp -= n; return tmp;}
-
- constexpr reference operator[](
diff erence_type n) const {return it_[n];}
-
- friend constexpr
-
diff erence_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 <class T>
- void operator,(T const &) = delete;
-};
-
-#endif // TEST_STD_VER > 17 && defined(__cpp_lib_concepts)
+#endif // TEST_STD_VER > 17
#endif // SUPPORT_TEST_ITERATORS_H
More information about the libcxx-commits
mailing list