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

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