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+=(difference_type n) |
12 | // requires advanceable<W>; |
13 | |
14 | #include <cassert> |
15 | #include <ranges> |
16 | #include <type_traits> |
17 | |
18 | #include "test_macros.h" |
19 | #include "../types.h" |
20 | |
21 | constexpr bool test() { |
22 | // When "_Start" is signed integer like. |
23 | { |
24 | std::ranges::iota_view<int> io(0); |
25 | auto iter1 = io.begin(); |
26 | auto iter2 = io.begin(); |
27 | assert(iter1 == iter2); |
28 | iter1 += 5; |
29 | assert(iter1 != iter2); |
30 | assert(iter1 == std::ranges::next(iter2, 5)); |
31 | |
32 | static_assert(std::is_reference_v<decltype(iter2 += 5)>); |
33 | } |
34 | |
35 | // When "_Start" is not integer like. |
36 | { |
37 | std::ranges::iota_view io(SomeInt(0)); |
38 | auto iter1 = io.begin(); |
39 | auto iter2 = io.begin(); |
40 | assert(iter1 == iter2); |
41 | iter1 += 5; |
42 | assert(iter1 != iter2); |
43 | assert(iter1 == std::ranges::next(iter2, 5)); |
44 | |
45 | static_assert(std::is_reference_v<decltype(iter2 += 5)>); |
46 | } |
47 | |
48 | // When "_Start" is unsigned integer like and n is greater than or equal to zero. |
49 | { |
50 | std::ranges::iota_view<unsigned> io(0); |
51 | auto iter1 = io.begin(); |
52 | auto iter2 = io.begin(); |
53 | assert(iter1 == iter2); |
54 | iter1 += 5; |
55 | assert(iter1 != iter2); |
56 | assert(iter1 == std::ranges::next(iter2, 5)); |
57 | |
58 | static_assert(std::is_reference_v<decltype(iter2 += 5)>); |
59 | } |
60 | { |
61 | std::ranges::iota_view<unsigned> io(0); |
62 | auto iter1 = io.begin(); |
63 | auto iter2 = io.begin(); |
64 | assert(iter1 == iter2); |
65 | iter1 += 0; |
66 | assert(iter1 == iter2); |
67 | } |
68 | |
69 | // When "_Start" is unsigned integer like and n is less than zero. |
70 | { |
71 | std::ranges::iota_view<unsigned> io(0); |
72 | auto iter1 = io.begin(); |
73 | auto iter2 = io.begin(); |
74 | assert(iter1 == iter2); |
75 | iter1 += 5; |
76 | assert(iter1 != iter2); |
77 | assert(iter1 == std::ranges::next(iter2, 5)); |
78 | |
79 | static_assert(std::is_reference_v<decltype(iter2 += 5)>); |
80 | } |
81 | |
82 | return true; |
83 | } |
84 | |
85 | int main(int, char**) { |
86 | test(); |
87 | static_assert(test()); |
88 | |
89 | return 0; |
90 | } |
91 | |