test_range<int, random_access_iterator_wrapper> c(a);
VERIFY( std::ranges::distance(c) == 10 );
- auto b = c.begin(), e = c.end();
+ auto b = c.begin();
+ auto e = c.end();
+ auto ei = std::ranges::next(b, e);
VERIFY( std::ranges::distance(b, e) == 10 );
- VERIFY( std::ranges::distance(e, b) == -10 );
+ VERIFY( std::ranges::distance(ei, b) == -10 );
- const auto cb = b, ce = e;
+ const auto cb = b;
+ const auto ce = e;
+ const auto cei = ei;
VERIFY( std::ranges::distance(cb, ce) == 10 );
- VERIFY( std::ranges::distance(ce, cb) == -10 );
+ VERIFY( std::ranges::distance(cei, cb) == -10 );
test_sized_range<int, random_access_iterator_wrapper> c2(a);
VERIFY( std::ranges::distance(c2) == 10 );
test_range<int, bidirectional_iterator_wrapper> c(a);
VERIFY( std::ranges::distance(c) == 2 );
- auto b = c.begin(), e = c.end();
+ auto b = c.begin();
+ auto e = c.end();
VERIFY( std::ranges::distance(b, e) == 2 );
- const auto cb = b, ce = e;
+ const auto cb = b;
+ const auto ce = e;
VERIFY( std::ranges::distance(cb, ce) == 2 );
test_sized_range<int, bidirectional_iterator_wrapper> c2(a);
test_range<int, forward_iterator_wrapper> c(a);
VERIFY( std::ranges::distance(c) == 3 );
- auto b = c.begin(), e = c.end();
+ auto b = c.begin();
+ auto e = c.end();
VERIFY( std::ranges::distance(b, e) == 3 );
- const auto cb = b, ce = e;
+ const auto cb = b;
+ const auto ce = e;
VERIFY( std::ranges::distance(cb, ce) == 3 );
test_sized_range<int, forward_iterator_wrapper> c2(a);
VERIFY( std::ranges::distance(c) == 0 );
c = test_range<int, input_iterator_wrapper>(a);
- auto b = c.begin(), e = c.end();
+ auto b = c.begin();
+ auto e = c.end();
VERIFY( std::ranges::distance(b, e) == 4 );
test_range<int, input_iterator_wrapper> c2(a);
- const auto cb = c2.begin(), ce = c2.end();
+ const auto cb = c2.begin();
+ const auto ce = c2.end();
VERIFY( std::ranges::distance(cb, ce) == 4 );
test_sized_range<int, input_iterator_wrapper> c3(a);
test_range<int, random_access_iterator_wrapper> r(a);
auto begin = r.begin();
auto end = r.end();
+ auto endi = std::ranges::next(begin, end);
VERIFY( *std::ranges::next(begin) == 1 );
VERIFY( std::ranges::next(begin, 0) == begin );
VERIFY( *std::ranges::next(begin, 1) == 1 );
VERIFY( *std::ranges::next(begin, 3) == 3 );
- VERIFY( *std::ranges::next(end, -4) == 6 );
+ VERIFY( *std::ranges::next(endi, -4) == 6 );
VERIFY( std::ranges::next(begin, begin) == begin );
VERIFY( std::ranges::next(begin, end) == end );
- VERIFY( std::ranges::next(end, end) == end );
- VERIFY( std::ranges::next(end, begin) == begin );
+ VERIFY( std::ranges::next(endi, end) == end );
+ VERIFY( std::ranges::next(endi, begin) == begin );
VERIFY( std::ranges::next(begin, 0, begin) == begin );
VERIFY( std::ranges::next(begin, 5, begin) == begin );
VERIFY( std::ranges::next(begin, -5, begin) == begin );
VERIFY( std::ranges::next(begin, 0, end) == begin );
VERIFY( *std::ranges::next(begin, 5, end) == 5 );
VERIFY( std::ranges::next(begin, 55, end) == end );
- VERIFY( std::ranges::next(end, 0, end) == end );
- VERIFY( std::ranges::next(end, -5, end) == end );
- VERIFY( std::ranges::next(end, -55, end) == end );
- VERIFY( std::ranges::next(end, 0, begin) == end );
- VERIFY( *std::ranges::next(end, -5, begin) == 5 );
- VERIFY( std::ranges::next(end, -55, begin) == begin );
+ VERIFY( std::ranges::next(endi, 0, end) == end );
+ VERIFY( std::ranges::next(endi, -5, end) == end );
+ VERIFY( std::ranges::next(endi, -55, end) == end );
+ VERIFY( std::ranges::next(endi, 0, begin) == end );
+ VERIFY( *std::ranges::next(endi, -5, begin) == 5 );
+ VERIFY( std::ranges::next(endi, -55, begin) == begin );
}
void
test_range<int, bidirectional_iterator_wrapper> r(a);
auto begin = r.begin();
auto end = r.end();
+ auto endi = std::ranges::next(begin, end);
VERIFY( *std::ranges::next(begin) == 1 );
VERIFY( std::ranges::next(begin, 0) == begin );
VERIFY( *std::ranges::next(begin, 1) == 1 );
VERIFY( *std::ranges::next(begin, 3) == 3 );
- VERIFY( *std::ranges::next(end, -4) == 6 );
+ VERIFY( *std::ranges::next(endi, -4) == 6 );
VERIFY( std::ranges::next(begin, begin) == begin );
VERIFY( std::ranges::next(begin, end) == end );
- VERIFY( std::ranges::next(end, end) == end );
- VERIFY( std::ranges::next(end, begin) == begin );
+ VERIFY( std::ranges::next(endi, end) == end );
+ VERIFY( std::ranges::next(endi, begin) == begin );
VERIFY( std::ranges::next(begin, 0, begin) == begin );
VERIFY( std::ranges::next(begin, 5, begin) == begin );
VERIFY( std::ranges::next(begin, -5, begin) == begin );
VERIFY( std::ranges::next(begin, 0, end) == begin );
VERIFY( *std::ranges::next(begin, 5, end) == 5 );
VERIFY( std::ranges::next(begin, 55, end) == end );
- VERIFY( std::ranges::next(end, 0, end) == end );
- VERIFY( std::ranges::next(end, -5, end) == end );
- VERIFY( std::ranges::next(end, -55, end) == end );
- VERIFY( std::ranges::next(end, 0, begin) == end );
- VERIFY( *std::ranges::next(end, -5, begin) == 5 );
- VERIFY( std::ranges::next(end, -55, begin) == begin );
+ VERIFY( std::ranges::next(endi, 0, end) == end );
+ VERIFY( std::ranges::next(endi, -5, end) == end );
+ VERIFY( std::ranges::next(endi, -55, end) == end );
+ VERIFY( std::ranges::next(endi, 0, begin) == end );
+ VERIFY( *std::ranges::next(endi, -5, begin) == 5 );
+ VERIFY( std::ranges::next(endi, -55, begin) == begin );
}
void
test_range<int, forward_iterator_wrapper> r(a);
auto begin = r.begin();
auto end = r.end();
+ auto endi = std::ranges::next(begin, end);
VERIFY( *std::ranges::next(begin) == 1 );
VERIFY( std::ranges::next(begin, 0) == begin );
VERIFY( *std::ranges::next(begin, 1) == 1 );
VERIFY( *std::ranges::next(begin, 3) == 3 );
VERIFY( std::ranges::next(begin, begin) == begin );
VERIFY( std::ranges::next(begin, end) == end );
- VERIFY( std::ranges::next(end, end) == end );
+ VERIFY( std::ranges::next(endi, end) == end );
VERIFY( std::ranges::next(begin, 0, begin) == begin );
VERIFY( std::ranges::next(begin, 5, begin) == begin );
VERIFY( std::ranges::next(begin, -5, begin) == begin );
VERIFY( std::ranges::next(begin, 0, end) == begin );
VERIFY( *std::ranges::next(begin, 5, end) == 5 );
VERIFY( std::ranges::next(begin, 55, end) == end );
- VERIFY( std::ranges::next(end, 0, end) == end );
- VERIFY( std::ranges::next(end, 5, end) == end );
- VERIFY( std::ranges::next(end, 55, end) == end );
- VERIFY( std::ranges::next(end, 0, begin) == end );
+ VERIFY( std::ranges::next(endi, 0, end) == end );
+ VERIFY( std::ranges::next(endi, 5, end) == end );
+ VERIFY( std::ranges::next(endi, 55, end) == end );
+ VERIFY( std::ranges::next(endi, 0, begin) == end );
}
void
test_range<int, input_iterator_wrapper> r2(a);
begin = r2.begin();
end = r2.end();
+ auto endi = std::ranges::next(begin, end);
+ // reset single-pass input range
+ r2.bounds.first = a;
iter = std::ranges::next(begin, 0, begin);
VERIFY( *iter == 0 );
iter = std::ranges::next(begin, 5, begin);
VERIFY( *iter == 0 );
iter = std::ranges::next(begin, 0, end);
VERIFY( *iter == 0 );
- iter = std::ranges::next(end, 0, begin);
+ iter = std::ranges::next(endi, 0, begin);
VERIFY( iter == end );
iter = std::ranges::next(begin, 5, end); // invalidates begin
VERIFY( *iter == 5 );
iter = std::ranges::next(iter, 55, end);
VERIFY( iter == end );
- iter = std::ranges::next(end, 0, end);
+ iter = std::ranges::next(endi, 0, end);
VERIFY( iter == end );
- iter = std::ranges::next(end, 5, end);
+ iter = std::ranges::next(endi, 5, end);
VERIFY( iter == end );
}
test_range<int, random_access_iterator_wrapper> r(a);
auto begin = r.begin();
auto end = r.end();
- VERIFY( *std::ranges::prev(end) == 9 );
+ auto endi = std::ranges::next(begin, end);
+ VERIFY( *std::ranges::prev(endi) == 9 );
VERIFY( std::ranges::prev(begin, 0) == begin );
- VERIFY( *std::ranges::prev(end, 1) == 9 );
- VERIFY( *std::ranges::prev(end, 3) == 7 );
+ VERIFY( *std::ranges::prev(endi, 1) == 9 );
+ VERIFY( *std::ranges::prev(endi, 3) == 7 );
VERIFY( *std::ranges::prev(begin, -4) == 4 );
VERIFY( std::ranges::prev(begin, 0, begin) == begin );
VERIFY( std::ranges::prev(begin, 5, begin) == begin );
VERIFY( std::ranges::prev(begin, -5, begin) == begin );
- VERIFY( std::ranges::prev(begin, 0, end) == begin );
- VERIFY( *std::ranges::prev(end, 5, begin) == 5 );
- VERIFY( std::ranges::prev(end, 55, begin) == begin );
- VERIFY( std::ranges::prev(end, 0, end) == end );
- VERIFY( std::ranges::prev(end, -5, end) == end );
- VERIFY( std::ranges::prev(end, -55, end) == end );
- VERIFY( std::ranges::prev(end, 0, begin) == end );
- VERIFY( *std::ranges::prev(begin, -5, end) == 5 );
- VERIFY( std::ranges::prev(begin, -55, end) == end );
+ VERIFY( std::ranges::prev(begin, 0, endi) == begin );
+ VERIFY( *std::ranges::prev(endi, 5, begin) == 5 );
+ VERIFY( std::ranges::prev(endi, 55, begin) == begin );
+ VERIFY( std::ranges::prev(endi, 0, endi) == end );
+ VERIFY( std::ranges::prev(endi, -5, endi) == end );
+ VERIFY( std::ranges::prev(endi, -55, endi) == end );
+ VERIFY( std::ranges::prev(endi, 0, begin) == end );
+ VERIFY( *std::ranges::prev(begin, -5, endi) == 5 );
+ VERIFY( std::ranges::prev(begin, -55, endi) == end );
}
void
test_range<int, bidirectional_iterator_wrapper> r(a);
auto begin = r.begin();
auto end = r.end();
- VERIFY( *std::ranges::prev(end) == 9 );
+ auto endi = std::ranges::next(begin, end);
+ VERIFY( *std::ranges::prev(endi) == 9 );
VERIFY( std::ranges::prev(begin, 0) == begin );
- VERIFY( *std::ranges::prev(end, 1) == 9 );
- VERIFY( *std::ranges::prev(end, 3) == 7 );
+ VERIFY( *std::ranges::prev(endi, 1) == 9 );
+ VERIFY( *std::ranges::prev(endi, 3) == 7 );
VERIFY( *std::ranges::prev(begin, -4) == 4 );
VERIFY( std::ranges::prev(begin, 0, begin) == begin );
VERIFY( std::ranges::prev(begin, 5, begin) == begin );
VERIFY( std::ranges::prev(begin, -5, begin) == begin );
- VERIFY( std::ranges::prev(begin, 0, end) == begin );
- VERIFY( *std::ranges::prev(end, 5, begin) == 5 );
- VERIFY( std::ranges::prev(end, 55, begin) == begin );
- VERIFY( std::ranges::prev(end, 0, end) == end );
- VERIFY( std::ranges::prev(end, -5, end) == end );
- VERIFY( std::ranges::prev(end, -55, end) == end );
- VERIFY( std::ranges::prev(end, 0, begin) == end );
- VERIFY( *std::ranges::prev(begin, -5, end) == 5 );
- VERIFY( std::ranges::prev(begin, -55, end) == end );
+ VERIFY( std::ranges::prev(begin, 0, endi) == begin );
+ VERIFY( *std::ranges::prev(endi, 5, begin) == 5 );
+ VERIFY( std::ranges::prev(endi, 55, begin) == begin );
+ VERIFY( std::ranges::prev(endi, 0, endi) == end );
+ VERIFY( std::ranges::prev(endi, -5, endi) == end );
+ VERIFY( std::ranges::prev(endi, -55, endi) == end );
+ VERIFY( std::ranges::prev(endi, 0, begin) == end );
+ VERIFY( *std::ranges::prev(begin, -5, endi) == 5 );
+ VERIFY( std::ranges::prev(begin, -55, endi) == end );
}
template<typename T>