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// <iterator>
12//
13// reverse_iterator
14//
15// template <class Iterator1, class Iterator2>
16// constexpr bool // constexpr in C++17
17// operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
18//
19// template <class Iterator1, class Iterator2>
20// constexpr bool // constexpr in C++17
21// operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
22//
23// template <class Iterator1, class Iterator2>
24// constexpr bool // constexpr in C++17
25// operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
26//
27// template <class Iterator1, class Iterator2>
28// constexpr bool // constexpr in C++17
29// operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
30//
31// template <class Iterator1, class Iterator2>
32// constexpr bool // constexpr in C++17
33// operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
34//
35// template <class Iterator1, class Iterator2>
36// constexpr bool // constexpr in C++17
37// operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
38//
39// template<class Iterator1, three_way_comparable_with<Iterator1> Iterator2>
40// constexpr compare_three_way_result_t<Iterator1, Iterator2>
41// operator<=>(const reverse_iterator<Iterator1>& x,
42// const reverse_iterator<Iterator2>& y);
43
44#include <iterator>
45#include <cassert>
46
47#include "test_macros.h"
48
49struct IterBase {
50 using iterator_category = std::bidirectional_iterator_tag;
51 using value_type = int;
52 using difference_type = std::ptrdiff_t;
53 using pointer = int*;
54 using reference = int&;
55
56 reference operator*() const;
57 pointer operator->() const;
58};
59
60template<class T> concept HasEqual = requires (T t) { t == t; };
61template<class T> concept HasNotEqual = requires (T t) { t != t; };
62template<class T> concept HasLess = requires (T t) { t < t; };
63template<class T> concept HasLessOrEqual = requires (T t) { t <= t; };
64template<class T> concept HasGreater = requires (T t) { t > t; };
65template<class T> concept HasGreaterOrEqual = requires (T t) { t >= t; };
66template<class T> concept HasSpaceship = requires (T t) { t <=> t; };
67
68// operator ==
69
70struct NoEqualityCompIter : IterBase {
71 bool operator!=(NoEqualityCompIter) const;
72 bool operator<(NoEqualityCompIter) const;
73 bool operator>(NoEqualityCompIter) const;
74 bool operator<=(NoEqualityCompIter) const;
75 bool operator>=(NoEqualityCompIter) const;
76};
77
78static_assert( HasEqual<std::reverse_iterator<int*>>);
79static_assert(!HasEqual<std::reverse_iterator<NoEqualityCompIter>>);
80static_assert( HasNotEqual<std::reverse_iterator<NoEqualityCompIter>>);
81static_assert( HasLess<std::reverse_iterator<NoEqualityCompIter>>);
82static_assert( HasLessOrEqual<std::reverse_iterator<NoEqualityCompIter>>);
83static_assert( HasGreater<std::reverse_iterator<NoEqualityCompIter>>);
84static_assert( HasGreaterOrEqual<std::reverse_iterator<NoEqualityCompIter>>);
85
86void Foo() {
87 std::reverse_iterator<NoEqualityCompIter> i;
88 (void)i;
89}
90
91// operator !=
92
93struct NoInequalityCompIter : IterBase {
94 bool operator<(NoInequalityCompIter) const;
95 bool operator>(NoInequalityCompIter) const;
96 bool operator<=(NoInequalityCompIter) const;
97 bool operator>=(NoInequalityCompIter) const;
98};
99
100static_assert( HasNotEqual<std::reverse_iterator<int*>>);
101static_assert(!HasNotEqual<std::reverse_iterator<NoInequalityCompIter>>);
102static_assert(!HasEqual<std::reverse_iterator<NoInequalityCompIter>>);
103static_assert( HasLess<std::reverse_iterator<NoInequalityCompIter>>);
104static_assert( HasLessOrEqual<std::reverse_iterator<NoInequalityCompIter>>);
105static_assert( HasGreater<std::reverse_iterator<NoInequalityCompIter>>);
106static_assert( HasGreaterOrEqual<std::reverse_iterator<NoInequalityCompIter>>);
107
108// operator <
109
110struct NoGreaterCompIter : IterBase {
111 bool operator==(NoGreaterCompIter) const;
112 bool operator!=(NoGreaterCompIter) const;
113 bool operator<(NoGreaterCompIter) const;
114 bool operator<=(NoGreaterCompIter) const;
115 bool operator>=(NoGreaterCompIter) const;
116};
117
118static_assert( HasLess<std::reverse_iterator<int*>>);
119static_assert(!HasLess<std::reverse_iterator<NoGreaterCompIter>>);
120static_assert( HasEqual<std::reverse_iterator<NoGreaterCompIter>>);
121static_assert( HasNotEqual<std::reverse_iterator<NoGreaterCompIter>>);
122static_assert( HasLessOrEqual<std::reverse_iterator<NoGreaterCompIter>>);
123static_assert( HasGreater<std::reverse_iterator<NoGreaterCompIter>>);
124static_assert( HasGreaterOrEqual<std::reverse_iterator<NoGreaterCompIter>>);
125
126// operator >
127
128struct NoLessCompIter : IterBase {
129 bool operator==(NoLessCompIter) const;
130 bool operator!=(NoLessCompIter) const;
131 bool operator>(NoLessCompIter) const;
132 bool operator<=(NoLessCompIter) const;
133 bool operator>=(NoLessCompIter) const;
134};
135
136static_assert( HasGreater<std::reverse_iterator<int*>>);
137static_assert(!HasGreater<std::reverse_iterator<NoLessCompIter>>);
138static_assert( HasEqual<std::reverse_iterator<NoLessCompIter>>);
139static_assert( HasNotEqual<std::reverse_iterator<NoLessCompIter>>);
140static_assert( HasLess<std::reverse_iterator<NoLessCompIter>>);
141static_assert( HasLessOrEqual<std::reverse_iterator<NoLessCompIter>>);
142static_assert( HasGreaterOrEqual<std::reverse_iterator<NoLessCompIter>>);
143
144// operator <=
145
146struct NoGreaterOrEqualCompIter : IterBase {
147 bool operator==(NoGreaterOrEqualCompIter) const;
148 bool operator!=(NoGreaterOrEqualCompIter) const;
149 bool operator<(NoGreaterOrEqualCompIter) const;
150 bool operator>(NoGreaterOrEqualCompIter) const;
151 bool operator<=(NoGreaterOrEqualCompIter) const;
152};
153
154static_assert( HasLessOrEqual<std::reverse_iterator<int*>>);
155static_assert(!HasLessOrEqual<std::reverse_iterator<NoGreaterOrEqualCompIter>>);
156static_assert( HasEqual<std::reverse_iterator<NoGreaterOrEqualCompIter>>);
157static_assert( HasNotEqual<std::reverse_iterator<NoGreaterOrEqualCompIter>>);
158static_assert( HasLess<std::reverse_iterator<NoGreaterOrEqualCompIter>>);
159static_assert( HasGreater<std::reverse_iterator<NoGreaterOrEqualCompIter>>);
160static_assert( HasGreaterOrEqual<std::reverse_iterator<NoGreaterOrEqualCompIter>>);
161
162// operator >=
163
164struct NoLessOrEqualCompIter : IterBase {
165 bool operator==(NoLessOrEqualCompIter) const;
166 bool operator!=(NoLessOrEqualCompIter) const;
167 bool operator<(NoLessOrEqualCompIter) const;
168 bool operator>(NoLessOrEqualCompIter) const;
169 bool operator>=(NoLessOrEqualCompIter) const;
170};
171
172static_assert( HasGreaterOrEqual<std::reverse_iterator<int*>>);
173static_assert(!HasGreaterOrEqual<std::reverse_iterator<NoLessOrEqualCompIter>>);
174static_assert( HasEqual<std::reverse_iterator<NoLessOrEqualCompIter>>);
175static_assert( HasNotEqual<std::reverse_iterator<NoLessOrEqualCompIter>>);
176static_assert( HasLess<std::reverse_iterator<NoLessOrEqualCompIter>>);
177static_assert( HasLessOrEqual<std::reverse_iterator<NoLessOrEqualCompIter>>);
178static_assert( HasGreater<std::reverse_iterator<NoLessOrEqualCompIter>>);
179
180// operator <=>
181
182static_assert( std::three_way_comparable_with<int*, int*>);
183static_assert( HasSpaceship<std::reverse_iterator<int*>>);
184static_assert(!std::three_way_comparable_with<NoEqualityCompIter, NoEqualityCompIter>);
185static_assert(!HasSpaceship<std::reverse_iterator<NoEqualityCompIter>>);
186static_assert(!std::three_way_comparable_with<NoInequalityCompIter, NoInequalityCompIter>);
187static_assert(!HasSpaceship<std::reverse_iterator<NoInequalityCompIter>>);
188static_assert(!std::three_way_comparable_with<NoGreaterCompIter, NoGreaterCompIter>);
189static_assert(!HasSpaceship<std::reverse_iterator<NoGreaterCompIter>>);
190static_assert(!std::three_way_comparable_with<NoLessCompIter, NoLessCompIter>);
191static_assert(!HasSpaceship<std::reverse_iterator<NoLessCompIter>>);
192static_assert(!std::three_way_comparable_with<NoGreaterOrEqualCompIter, NoGreaterOrEqualCompIter>);
193static_assert(!HasSpaceship<std::reverse_iterator<NoGreaterOrEqualCompIter>>);
194static_assert(!std::three_way_comparable_with<NoLessOrEqualCompIter, NoLessOrEqualCompIter>);
195static_assert(!HasSpaceship<std::reverse_iterator<NoLessOrEqualCompIter>>);
196

source code of libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/sfinae.compile.pass.cpp