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 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
11
12 // ranges::prev(it)
13
14 #include <iterator>
15 #include <cassert>
16
17 #include "test_iterators.h"
18
19 template <class It>
check(int * first,int * expected)20 constexpr void check(int* first, int* expected) {
21 It it(first);
22 std::same_as<It> auto result = std::ranges::prev(std::move(it));
23 assert(base(result) == expected);
24 }
25
test()26 constexpr bool test() {
27 int range[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
28
29 for (int n = 1; n != 10; ++n) {
30 check<bidirectional_iterator<int*>>(range+n, range+n-1);
31 check<random_access_iterator<int*>>(range+n, range+n-1);
32 check<contiguous_iterator<int*>>( range+n, range+n-1);
33 check<int*>( range+n, range+n-1);
34 }
35
36 return true;
37 }
38
39
main(int,char **)40 int main(int, char**) {
41 test();
42 static_assert(test());
43 return 0;
44 }
45