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// constexpr iterator& operator--() requires decrementable<W>;
12// constexpr iterator operator--(int) requires decrementable<W>;
13
14#include <cassert>
15#include <ranges>
16#include <type_traits>
17
18#include "test_macros.h"
19#include "../types.h"
20
21template<class T>
22concept Decrementable =
23 requires(T i) {
24 --i;
25 } ||
26 requires(T i) {
27 i--;
28 };
29
30constexpr bool test() {
31 {
32 std::ranges::iota_view<int> io(0);
33 auto iter1 = std::next(io.begin());
34 auto iter2 = std::next(io.begin());
35 assert(iter1 == iter2);
36 assert(--iter1 != iter2--);
37 assert(iter1 == iter2);
38
39 static_assert(!std::is_reference_v<decltype(iter2--)>);
40 static_assert( std::is_reference_v<decltype(--iter2)>);
41 static_assert(std::same_as<std::remove_reference_t<decltype(--iter2)>, decltype(iter2--)>);
42 }
43 {
44 std::ranges::iota_view io(SomeInt(0));
45 auto iter1 = std::next(io.begin());
46 auto iter2 = std::next(io.begin());
47 assert(iter1 == iter2);
48 assert(--iter1 != iter2--);
49 assert(iter1 == iter2);
50
51 static_assert(!std::is_reference_v<decltype(iter2--)>);
52 static_assert( std::is_reference_v<decltype(--iter2)>);
53 static_assert(std::same_as<std::remove_reference_t<decltype(--iter2)>, decltype(iter2--)>);
54 }
55
56 static_assert(!Decrementable<std::ranges::iota_view<NotDecrementable>>);
57
58 return true;
59}
60
61int main(int, char**) {
62 test();
63 static_assert(test());
64
65 return 0;
66}
67

source code of libcxx/test/std/ranges/range.factories/range.iota.view/iterator/decrement.pass.cpp