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, bound)
12
13#include <iterator>
14
15#include <cassert>
16#include <concepts>
17#include <utility>
18
19#include "test_iterators.h"
20
21template <typename It>
22constexpr void check(int* first, int* last, std::iter_difference_t<It> n, int* expected) {
23 It it(first);
24 auto sent = sentinel_wrapper(It(last));
25
26 std::same_as<It> auto result = std::ranges::next(std::move(it), n, sent);
27 assert(base(result) == expected);
28}
29
30constexpr bool test() {
31 int range[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
32
33 for (int size = 0; size != 10; ++size) {
34 for (int n = 0; n != 20; ++n) {
35 int* expected = n > size ? range + size : range + n;
36 check<cpp17_input_iterator<int*>>( range, range+size, n, expected);
37 check<cpp20_input_iterator<int*>>( range, range+size, n, expected);
38 check<forward_iterator<int*>>( range, range+size, n, expected);
39 check<bidirectional_iterator<int*>>(range, range+size, n, expected);
40 check<random_access_iterator<int*>>(range, range+size, n, expected);
41 check<contiguous_iterator<int*>>( range, range+size, n, expected);
42 check<int*>( range, range+size, n, expected);
43 }
44 }
45
46 return true;
47}
48
49int main(int, char**) {
50 assert(test());
51 static_assert(test());
52 return 0;
53}
54

source code of libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_count_sentinel.pass.cpp