| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 10 |
|
| 11 |
// ranges::next(it, n) |
| 12 |
|
| 13 |
#include <iterator> |
| 14 |
|
| 15 |
#include <cassert> |
| 16 |
#include <concepts> |
| 17 |
#include <utility> |
| 18 |
|
| 19 |
#include "test_iterators.h" |
| 20 |
|
| 21 |
template <typename It> |
| 22 |
constexpr void check(int* first, std::iter_difference_t<It> n, int* expected) { |
| 23 |
It it(first); |
| 24 |
std::same_as<It> auto result = std::ranges::next(std::move(it), n); |
| 25 |
assert(base(result) == expected); |
| 26 |
} |
| 27 |
|
| 28 |
constexpr bool test() { |
| 29 |
int range[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 30 |
|
| 31 |
// Check next() forward |
| 32 |
for (int n = 0; n != 10; ++n) { |
| 33 |
check<cpp17_input_iterator<int*>>( range, n, range+n); |
| 34 |
check<cpp20_input_iterator<int*>>( range, n, range+n); |
| 35 |
check<forward_iterator<int*>>( range, n, range+n); |
| 36 |
check<bidirectional_iterator<int*>>(range, n, range+n); |
| 37 |
check<random_access_iterator<int*>>(range, n, range+n); |
| 38 |
check<contiguous_iterator<int*>>( range, n, range+n); |
| 39 |
check<int*>( range, n, range+n); |
| 40 |
check<cpp17_output_iterator<int*> >(range, n, range+n); |
| 41 |
} |
| 42 |
|
| 43 |
// Check next() backward |
| 44 |
for (int n = 0; n != 10; ++n) { |
| 45 |
check<bidirectional_iterator<int*>>(range+9, -n, range+9 - n); |
| 46 |
check<random_access_iterator<int*>>(range+9, -n, range+9 - n); |
| 47 |
check<contiguous_iterator<int*>>( range+9, -n, range+9 - n); |
| 48 |
check<int*>( range+9, -n, range+9 - n); |
| 49 |
} |
| 50 |
|
| 51 |
return true; |
| 52 |
} |
| 53 |
|
| 54 |
int main(int, char**) { |
| 55 |
test(); |
| 56 |
static_assert(test()); |
| 57 |
return 0; |
| 58 |
} |