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

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