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 bool operator==(const iterator& x, const iterator& y); |
12 | |
13 | #include <algorithm> |
14 | #include <cassert> |
15 | #include <concepts> |
16 | #include <ranges> |
17 | |
18 | #include "test_iterators.h" |
19 | |
20 | template <class Iter> |
21 | constexpr void testOne() { |
22 | using Range = std::ranges::subrange<Iter>; |
23 | using SplitView = std::ranges::split_view<Range, std::ranges::single_view<int>>; |
24 | static_assert(std::ranges::common_range<SplitView>); |
25 | |
26 | { |
27 | // simple test |
28 | { |
29 | int buffer[] = {0, 1, 2, -1, 4, 5, 6}; |
30 | Range input(Iter{buffer}, Iter{buffer + 7}); |
31 | SplitView sv(input, -1); |
32 | auto b = sv.begin(), e = sv.end(); |
33 | |
34 | assert(b == b); |
35 | assert(!(b != b)); |
36 | |
37 | assert(e == e); |
38 | assert(!(e != e)); |
39 | |
40 | assert(!(b == e)); |
41 | assert(b != e); |
42 | |
43 | std::advance(b, 2); |
44 | assert(b == b); |
45 | assert(!(b != b)); |
46 | |
47 | assert(e == e); |
48 | assert(!(e != e)); |
49 | |
50 | assert(b == e); |
51 | assert(!(b != e)); |
52 | } |
53 | |
54 | // iterator at trailing empty position should not equal to end |
55 | { |
56 | int buffer[] = {0, 1, 2, -1}; |
57 | Range input(Iter{buffer}, Iter{buffer + 4}); |
58 | SplitView sv(input, -1); |
59 | auto b = sv.begin(), e = sv.end(); |
60 | |
61 | ++b; // cur points to end but trailing_empty is true |
62 | |
63 | assert(b != e); |
64 | assert(!(b == e)); |
65 | |
66 | ++b; |
67 | assert(b == e); |
68 | assert(!(b != e)); |
69 | } |
70 | |
71 | // Default-constructed iterators compare equal. |
72 | { |
73 | int buffer[] = {0, 1, 2, -1, 4, 5, 6}; |
74 | Range input(Iter{buffer}, Iter{buffer + 7}); |
75 | std::ranges::split_view sv(buffer, -1); |
76 | using SplitIter = decltype(sv.begin()); |
77 | SplitIter i1, i2; |
78 | assert(i1 == i2); |
79 | assert(!(i1 != i2)); |
80 | } |
81 | } |
82 | } |
83 | |
84 | constexpr bool test() { |
85 | testOne<forward_iterator<int*>>(); |
86 | testOne<bidirectional_iterator<int*>>(); |
87 | testOne<random_access_iterator<int*>>(); |
88 | testOne<contiguous_iterator<int*>>(); |
89 | testOne<int*>(); |
90 | |
91 | return true; |
92 | } |
93 | |
94 | int main(int, char**) { |
95 | test(); |
96 | static_assert(test()); |
97 | |
98 | return 0; |
99 | } |
100 | |