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