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, c++20
10
11// repeat_view::<iterator>::operator{==,<=>}
12
13#include <ranges>
14#include <cassert>
15#include <concepts>
16
17constexpr bool test() {
18 // Test unbound
19 {
20 using R = std::ranges::repeat_view<int>;
21 static_assert(std::three_way_comparable<std::ranges::iterator_t<R>>);
22
23 std::ranges::repeat_view<int> r(42);
24 auto iter1 = r.begin();
25 auto iter2 = iter1 + 1;
26
27 static_assert(std::same_as<decltype(iter1 == iter2), bool>);
28
29 assert(iter1 == iter1);
30 assert(!(iter1 == iter2));
31 assert(iter2 == iter2);
32
33 assert(!(iter1 < iter1));
34 assert(iter1 < iter2);
35 assert(!(iter2 < iter1));
36 assert(iter1 <= iter1);
37 assert(iter1 <= iter2);
38 assert(!(iter2 <= iter1));
39 assert(!(iter1 > iter1));
40 assert(!(iter1 > iter2));
41 assert(iter2 > iter1);
42 assert(iter1 >= iter1);
43 assert(!(iter1 >= iter2));
44 assert(iter2 >= iter1);
45 assert(iter1 == iter1);
46 assert(!(iter1 == iter2));
47 assert(iter2 == iter2);
48 assert(!(iter1 != iter1));
49 assert(iter1 != iter2);
50 assert(!(iter2 != iter2));
51
52 assert((iter1 <=> iter2) == std::strong_ordering::less);
53 assert((iter1 <=> iter1) == std::strong_ordering::equal);
54 assert((iter2 <=> iter1) == std::strong_ordering::greater);
55
56 static_assert(std::same_as<decltype(iter1 <=> iter2), std::strong_ordering>);
57 }
58
59 // Test bound
60 {
61 using R = std::ranges::repeat_view<int, int>;
62 static_assert(std::three_way_comparable<std::ranges::iterator_t<R>>);
63
64 std::ranges::repeat_view<int, int> r(42, 10);
65 auto iter1 = r.begin();
66 auto iter2 = iter1 + 1;
67
68 static_assert(std::same_as<decltype(iter1 == iter2), bool>);
69
70 assert(iter1 == iter1);
71 assert(!(iter1 == iter2));
72 assert(iter2 == iter2);
73
74 assert(!(iter1 < iter1));
75 assert(iter1 < iter2);
76 assert(!(iter2 < iter1));
77 assert(iter1 <= iter1);
78 assert(iter1 <= iter2);
79 assert(!(iter2 <= iter1));
80 assert(!(iter1 > iter1));
81 assert(!(iter1 > iter2));
82 assert(iter2 > iter1);
83 assert(iter1 >= iter1);
84 assert(!(iter1 >= iter2));
85 assert(iter2 >= iter1);
86 assert(iter1 == iter1);
87 assert(!(iter1 == iter2));
88 assert(iter2 == iter2);
89 assert(!(iter1 != iter1));
90 assert(iter1 != iter2);
91 assert(!(iter2 != iter2));
92
93 assert((iter1 <=> iter2) == std::strong_ordering::less);
94 assert((iter1 <=> iter1) == std::strong_ordering::equal);
95 assert((iter2 <=> iter1) == std::strong_ordering::greater);
96 }
97
98 return true;
99}
100
101int main(int, char**) {
102 test();
103 static_assert(test());
104
105 return 0;
106}
107

source code of libcxx/test/std/ranges/range.factories/range.repeat.view/iterator/compare.pass.cpp