Skip to content

Commit d5006e5

Browse files
committed
WIP: Add missing requirements for random access iterators
In this patch, also add all the missing checks in existing algorithms and add tests for those. This can be done before the large refactoring
1 parent 4a526f2 commit d5006e5

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

libcxx/test/support/test_iterators.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,9 +1484,14 @@ class iterator_wrapper {
14841484
return tmp;
14851485
}
14861486

1487-
iterator_wrapper& operator+=(difference_type i) {
1487+
Derived& operator+=(difference_type i) {
14881488
iter_ += i;
1489-
return *this;
1489+
return static_cast<Derived&>(*this);
1490+
}
1491+
1492+
Derived& operator-=(difference_type i) {
1493+
iter_ -= i;
1494+
return static_cast<Derived&>(*this);
14901495
}
14911496

14921497
friend decltype(iter_ - iter_) operator-(const iterator_wrapper& lhs, const iterator_wrapper& rhs) {
@@ -1503,8 +1508,17 @@ class iterator_wrapper {
15031508
return iter;
15041509
}
15051510

1511+
friend Derived operator+(difference_type i, Derived iter) {
1512+
return iter + i;
1513+
}
1514+
15061515
friend bool operator==(const iterator_wrapper& lhs, const iterator_wrapper& rhs) { return lhs.iter_ == rhs.iter_; }
15071516
friend bool operator!=(const iterator_wrapper& lhs, const iterator_wrapper& rhs) { return lhs.iter_ != rhs.iter_; }
1517+
1518+
friend bool operator>(const iterator_wrapper& lhs, const iterator_wrapper& rhs) { return lhs.iter_ > rhs.iter_; }
1519+
friend bool operator<(const iterator_wrapper& lhs, const iterator_wrapper& rhs) { return lhs.iter_ < rhs.iter_; }
1520+
friend bool operator<=(const iterator_wrapper& lhs, const iterator_wrapper& rhs) { return lhs.iter_ <= rhs.iter_; }
1521+
friend bool operator>=(const iterator_wrapper& lhs, const iterator_wrapper& rhs) { return lhs.iter_ >= rhs.iter_; }
15081522
};
15091523

15101524
class iterator_error : std::runtime_error {

0 commit comments

Comments
 (0)