Line data Source code
1 : // -*- C++ -*-
2 : //===----------------------------------------------------------------------===//
3 : //
4 : // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 : // See https://llvm.org/LICENSE.txt for license information.
6 : // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 : //
8 : //===----------------------------------------------------------------------===//
9 :
10 : #ifndef _LIBCPP___ITERATOR_REVERSE_ITERATOR_H
11 : #define _LIBCPP___ITERATOR_REVERSE_ITERATOR_H
12 :
13 : #include <__algorithm/unwrap_iter.h>
14 : #include <__compare/compare_three_way_result.h>
15 : #include <__compare/three_way_comparable.h>
16 : #include <__concepts/convertible_to.h>
17 : #include <__config>
18 : #include <__iterator/advance.h>
19 : #include <__iterator/concepts.h>
20 : #include <__iterator/incrementable_traits.h>
21 : #include <__iterator/iter_move.h>
22 : #include <__iterator/iter_swap.h>
23 : #include <__iterator/iterator.h>
24 : #include <__iterator/iterator_traits.h>
25 : #include <__iterator/next.h>
26 : #include <__iterator/prev.h>
27 : #include <__iterator/readable_traits.h>
28 : #include <__iterator/segmented_iterator.h>
29 : #include <__memory/addressof.h>
30 : #include <__ranges/access.h>
31 : #include <__ranges/concepts.h>
32 : #include <__ranges/subrange.h>
33 : #include <__type_traits/conditional.h>
34 : #include <__type_traits/enable_if.h>
35 : #include <__type_traits/is_assignable.h>
36 : #include <__type_traits/is_convertible.h>
37 : #include <__type_traits/is_nothrow_copy_constructible.h>
38 : #include <__type_traits/is_pointer.h>
39 : #include <__type_traits/is_same.h>
40 : #include <__utility/declval.h>
41 : #include <__utility/move.h>
42 :
43 : #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
44 : # pragma GCC system_header
45 : #endif
46 :
47 : _LIBCPP_BEGIN_NAMESPACE_STD
48 :
49 : _LIBCPP_SUPPRESS_DEPRECATED_PUSH
50 : template <class _Iter>
51 : class _LIBCPP_TEMPLATE_VIS reverse_iterator
52 : #if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
53 : : public iterator<typename iterator_traits<_Iter>::iterator_category,
54 : typename iterator_traits<_Iter>::value_type,
55 : typename iterator_traits<_Iter>::difference_type,
56 : typename iterator_traits<_Iter>::pointer,
57 : typename iterator_traits<_Iter>::reference>
58 : #endif
59 : {
60 : _LIBCPP_SUPPRESS_DEPRECATED_POP
61 : private:
62 : #ifndef _LIBCPP_ABI_NO_ITERATOR_BASES
63 : _Iter __t_; // no longer used as of LWG #2360, not removed due to ABI break
64 : #endif
65 :
66 : #if _LIBCPP_STD_VER > 17
67 : static_assert(__is_cpp17_bidirectional_iterator<_Iter>::value || bidirectional_iterator<_Iter>,
68 : "reverse_iterator<It> requires It to be a bidirectional iterator.");
69 : #endif // _LIBCPP_STD_VER > 17
70 :
71 : protected:
72 : _Iter current;
73 : public:
74 : using iterator_type = _Iter;
75 :
76 : using iterator_category = _If<__is_cpp17_random_access_iterator<_Iter>::value,
77 : random_access_iterator_tag,
78 : typename iterator_traits<_Iter>::iterator_category>;
79 : using pointer = typename iterator_traits<_Iter>::pointer;
80 : #if _LIBCPP_STD_VER > 17
81 : using iterator_concept = _If<random_access_iterator<_Iter>, random_access_iterator_tag, bidirectional_iterator_tag>;
82 : using value_type = iter_value_t<_Iter>;
83 : using difference_type = iter_difference_t<_Iter>;
84 : using reference = iter_reference_t<_Iter>;
85 : #else
86 : using value_type = typename iterator_traits<_Iter>::value_type;
87 : using difference_type = typename iterator_traits<_Iter>::difference_type;
88 : using reference = typename iterator_traits<_Iter>::reference;
89 : #endif
90 :
91 : #ifndef _LIBCPP_ABI_NO_ITERATOR_BASES
92 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
93 : reverse_iterator() : __t_(), current() {}
94 :
95 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
96 234720 : explicit reverse_iterator(_Iter __x) : __t_(__x), current(__x) {}
97 :
98 : template <class _Up, class = __enable_if_t<
99 : !is_same<_Up, _Iter>::value && is_convertible<_Up const&, _Iter>::value
100 : > >
101 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
102 : reverse_iterator(const reverse_iterator<_Up>& __u)
103 : : __t_(__u.base()), current(__u.base())
104 : { }
105 :
106 : template <class _Up, class = __enable_if_t<
107 : !is_same<_Up, _Iter>::value &&
108 : is_convertible<_Up const&, _Iter>::value &&
109 : is_assignable<_Iter&, _Up const&>::value
110 : > >
111 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
112 : reverse_iterator& operator=(const reverse_iterator<_Up>& __u) {
113 : __t_ = current = __u.base();
114 : return *this;
115 : }
116 : #else
117 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
118 : reverse_iterator() : current() {}
119 :
120 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
121 : explicit reverse_iterator(_Iter __x) : current(__x) {}
122 :
123 : template <class _Up, class = __enable_if_t<
124 : !is_same<_Up, _Iter>::value && is_convertible<_Up const&, _Iter>::value
125 : > >
126 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
127 : reverse_iterator(const reverse_iterator<_Up>& __u)
128 : : current(__u.base())
129 : { }
130 :
131 : template <class _Up, class = __enable_if_t<
132 : !is_same<_Up, _Iter>::value &&
133 : is_convertible<_Up const&, _Iter>::value &&
134 : is_assignable<_Iter&, _Up const&>::value
135 : > >
136 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
137 : reverse_iterator& operator=(const reverse_iterator<_Up>& __u) {
138 : current = __u.base();
139 : return *this;
140 : }
141 : #endif
142 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
143 270592 : _Iter base() const {return current;}
144 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
145 153232 : reference operator*() const {_Iter __tmp = current; return *--__tmp;}
146 :
147 : #if _LIBCPP_STD_VER > 17
148 : _LIBCPP_INLINE_VISIBILITY
149 : constexpr pointer operator->() const
150 : requires is_pointer_v<_Iter> || requires(const _Iter __i) { __i.operator->(); }
151 : {
152 : if constexpr (is_pointer_v<_Iter>) {
153 : return std::prev(current);
154 : } else {
155 : return std::prev(current).operator->();
156 : }
157 : }
158 : #else
159 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
160 3321 : pointer operator->() const {
161 3321 : return std::addressof(operator*());
162 : }
163 : #endif // _LIBCPP_STD_VER > 17
164 :
165 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
166 153232 : reverse_iterator& operator++() {--current; return *this;}
167 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
168 : reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
169 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
170 0 : reverse_iterator& operator--() {++current; return *this;}
171 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
172 : reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
173 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
174 : reverse_iterator operator+(difference_type __n) const {return reverse_iterator(current - __n);}
175 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
176 : reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
177 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
178 : reverse_iterator operator-(difference_type __n) const {return reverse_iterator(current + __n);}
179 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
180 : reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
181 : _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
182 : reference operator[](difference_type __n) const {return *(*this + __n);}
183 :
184 : #if _LIBCPP_STD_VER > 17
185 : _LIBCPP_HIDE_FROM_ABI friend constexpr
186 : iter_rvalue_reference_t<_Iter> iter_move(const reverse_iterator& __i)
187 : noexcept(is_nothrow_copy_constructible_v<_Iter> &&
188 : noexcept(ranges::iter_move(--std::declval<_Iter&>()))) {
189 : auto __tmp = __i.base();
190 : return ranges::iter_move(--__tmp);
191 : }
192 :
193 : template <indirectly_swappable<_Iter> _Iter2>
194 : _LIBCPP_HIDE_FROM_ABI friend constexpr
195 : void iter_swap(const reverse_iterator& __x, const reverse_iterator<_Iter2>& __y)
196 : noexcept(is_nothrow_copy_constructible_v<_Iter> &&
197 : is_nothrow_copy_constructible_v<_Iter2> &&
198 : noexcept(ranges::iter_swap(--std::declval<_Iter&>(), --std::declval<_Iter2&>()))) {
199 : auto __xtmp = __x.base();
200 : auto __ytmp = __y.base();
201 : ranges::iter_swap(--__xtmp, --__ytmp);
202 : }
203 : #endif // _LIBCPP_STD_VER > 17
204 : };
205 :
206 : template <class _Iter1, class _Iter2>
207 : inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
208 : bool
209 : operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
210 : #if _LIBCPP_STD_VER > 17
211 : requires requires {
212 : { __x.base() == __y.base() } -> convertible_to<bool>;
213 : }
214 : #endif // _LIBCPP_STD_VER > 17
215 : {
216 : return __x.base() == __y.base();
217 : }
218 :
219 : template <class _Iter1, class _Iter2>
220 : inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
221 : bool
222 : operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
223 : #if _LIBCPP_STD_VER > 17
224 : requires requires {
225 : { __x.base() > __y.base() } -> convertible_to<bool>;
226 : }
227 : #endif // _LIBCPP_STD_VER > 17
228 : {
229 : return __x.base() > __y.base();
230 : }
231 :
232 : template <class _Iter1, class _Iter2>
233 : inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
234 : bool
235 115736 : operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
236 : #if _LIBCPP_STD_VER > 17
237 : requires requires {
238 : { __x.base() != __y.base() } -> convertible_to<bool>;
239 : }
240 : #endif // _LIBCPP_STD_VER > 17
241 : {
242 115736 : return __x.base() != __y.base();
243 : }
244 :
245 : template <class _Iter1, class _Iter2>
246 : inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
247 : bool
248 : operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
249 : #if _LIBCPP_STD_VER > 17
250 : requires requires {
251 : { __x.base() < __y.base() } -> convertible_to<bool>;
252 : }
253 : #endif // _LIBCPP_STD_VER > 17
254 : {
255 : return __x.base() < __y.base();
256 : }
257 :
258 : template <class _Iter1, class _Iter2>
259 : inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
260 : bool
261 : operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
262 : #if _LIBCPP_STD_VER > 17
263 : requires requires {
264 : { __x.base() <= __y.base() } -> convertible_to<bool>;
265 : }
266 : #endif // _LIBCPP_STD_VER > 17
267 : {
268 : return __x.base() <= __y.base();
269 : }
270 :
271 : template <class _Iter1, class _Iter2>
272 : inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
273 : bool
274 : operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
275 : #if _LIBCPP_STD_VER > 17
276 : requires requires {
277 : { __x.base() >= __y.base() } -> convertible_to<bool>;
278 : }
279 : #endif // _LIBCPP_STD_VER > 17
280 : {
281 : return __x.base() >= __y.base();
282 : }
283 :
284 : #if _LIBCPP_STD_VER > 17
285 : template <class _Iter1, three_way_comparable_with<_Iter1> _Iter2>
286 : _LIBCPP_HIDE_FROM_ABI constexpr
287 : compare_three_way_result_t<_Iter1, _Iter2>
288 : operator<=>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
289 : {
290 : return __y.base() <=> __x.base();
291 : }
292 : #endif // _LIBCPP_STD_VER > 17
293 :
294 : #ifndef _LIBCPP_CXX03_LANG
295 : template <class _Iter1, class _Iter2>
296 : inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
297 : auto
298 : operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
299 : -> decltype(__y.base() - __x.base())
300 : {
301 : return __y.base() - __x.base();
302 : }
303 : #else
304 : template <class _Iter1, class _Iter2>
305 : inline _LIBCPP_INLINE_VISIBILITY
306 : typename reverse_iterator<_Iter1>::difference_type
307 : operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
308 : {
309 : return __y.base() - __x.base();
310 : }
311 : #endif
312 :
313 : template <class _Iter>
314 : inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
315 : reverse_iterator<_Iter>
316 : operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
317 : {
318 : return reverse_iterator<_Iter>(__x.base() - __n);
319 : }
320 :
321 : #if _LIBCPP_STD_VER > 17
322 : template <class _Iter1, class _Iter2>
323 : requires (!sized_sentinel_for<_Iter1, _Iter2>)
324 : inline constexpr bool disable_sized_sentinel_for<reverse_iterator<_Iter1>, reverse_iterator<_Iter2>> = true;
325 : #endif // _LIBCPP_STD_VER > 17
326 :
327 : #if _LIBCPP_STD_VER > 11
328 : template <class _Iter>
329 : inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17
330 : reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
331 : {
332 : return reverse_iterator<_Iter>(__i);
333 : }
334 : #endif
335 :
336 : #if _LIBCPP_STD_VER <= 17
337 : template <class _Iter>
338 : using __unconstrained_reverse_iterator = reverse_iterator<_Iter>;
339 : #else
340 :
341 : // __unconstrained_reverse_iterator allows us to use reverse iterators in the implementation of algorithms by working
342 : // around a language issue in C++20.
343 : // In C++20, when a reverse iterator wraps certain C++20-hostile iterators, calling comparison operators on it will
344 : // result in a compilation error. However, calling comparison operators on the pristine hostile iterator is not
345 : // an error. Thus, we cannot use reverse_iterators in the implementation of an algorithm that accepts a
346 : // C++20-hostile iterator. This class is an internal workaround -- it is a copy of reverse_iterator with
347 : // tweaks to make it support hostile iterators.
348 : //
349 : // A C++20-hostile iterator is one that defines a comparison operator where one of the arguments is an exact match
350 : // and the other requires an implicit conversion, for example:
351 : // friend bool operator==(const BaseIter&, const DerivedIter&);
352 : //
353 : // C++20 rules for rewriting equality operators create another overload of this function with parameters reversed:
354 : // friend bool operator==(const DerivedIter&, const BaseIter&);
355 : //
356 : // This creates an ambiguity in overload resolution.
357 : //
358 : // Clang treats this ambiguity differently in different contexts. When operator== is actually called in the function
359 : // body, the code is accepted with a warning. When a concept requires operator== to be a valid expression, however,
360 : // it evaluates to false. Thus, the implementation of reverse_iterator::operator== can actually call operator== on its
361 : // base iterators, but the constraints on reverse_iterator::operator== prevent it from being considered during overload
362 : // resolution. This class simply removes the problematic constraints from comparison functions.
363 : template <class _Iter>
364 : class __unconstrained_reverse_iterator {
365 : _Iter __iter_;
366 :
367 : public:
368 : static_assert(__is_cpp17_bidirectional_iterator<_Iter>::value || bidirectional_iterator<_Iter>);
369 :
370 : using iterator_type = _Iter;
371 : using iterator_category =
372 : _If<__is_cpp17_random_access_iterator<_Iter>::value, random_access_iterator_tag, __iterator_category_type<_Iter>>;
373 : using pointer = __iterator_pointer_type<_Iter>;
374 : using value_type = iter_value_t<_Iter>;
375 : using difference_type = iter_difference_t<_Iter>;
376 : using reference = iter_reference_t<_Iter>;
377 :
378 : _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator() = default;
379 : _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator(const __unconstrained_reverse_iterator&) = default;
380 : _LIBCPP_HIDE_FROM_ABI constexpr explicit __unconstrained_reverse_iterator(_Iter __iter) : __iter_(__iter) {}
381 :
382 : _LIBCPP_HIDE_FROM_ABI constexpr _Iter base() const { return __iter_; }
383 : _LIBCPP_HIDE_FROM_ABI constexpr reference operator*() const {
384 : auto __tmp = __iter_;
385 : return *--__tmp;
386 : }
387 :
388 : _LIBCPP_HIDE_FROM_ABI constexpr pointer operator->() const {
389 : if constexpr (is_pointer_v<_Iter>) {
390 : return std::prev(__iter_);
391 : } else {
392 : return std::prev(__iter_).operator->();
393 : }
394 : }
395 :
396 : _LIBCPP_HIDE_FROM_ABI friend constexpr
397 : iter_rvalue_reference_t<_Iter> iter_move(const __unconstrained_reverse_iterator& __i)
398 : noexcept(is_nothrow_copy_constructible_v<_Iter> &&
399 : noexcept(ranges::iter_move(--std::declval<_Iter&>()))) {
400 : auto __tmp = __i.base();
401 : return ranges::iter_move(--__tmp);
402 : }
403 :
404 : _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator& operator++() {
405 : --__iter_;
406 : return *this;
407 : }
408 :
409 : _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator operator++(int) {
410 : auto __tmp = *this;
411 : --__iter_;
412 : return __tmp;
413 : }
414 :
415 : _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator& operator--() {
416 : ++__iter_;
417 : return *this;
418 : }
419 :
420 : _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator operator--(int) {
421 : auto __tmp = *this;
422 : ++__iter_;
423 : return __tmp;
424 : }
425 :
426 : _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator& operator+=(difference_type __n) {
427 : __iter_ -= __n;
428 : return *this;
429 : }
430 :
431 : _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator& operator-=(difference_type __n) {
432 : __iter_ += __n;
433 : return *this;
434 : }
435 :
436 : _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator operator+(difference_type __n) const {
437 : return __unconstrained_reverse_iterator(__iter_ - __n);
438 : }
439 :
440 : _LIBCPP_HIDE_FROM_ABI constexpr __unconstrained_reverse_iterator operator-(difference_type __n) const {
441 : return __unconstrained_reverse_iterator(__iter_ + __n);
442 : }
443 :
444 : _LIBCPP_HIDE_FROM_ABI constexpr difference_type operator-(const __unconstrained_reverse_iterator& __other) const {
445 : return __other.__iter_ - __iter_;
446 : }
447 :
448 : _LIBCPP_HIDE_FROM_ABI constexpr auto operator[](difference_type __n) const { return *(*this + __n); }
449 :
450 : // Deliberately unconstrained unlike the comparison functions in `reverse_iterator` -- see the class comment for the
451 : // rationale.
452 : _LIBCPP_HIDE_FROM_ABI friend constexpr bool
453 : operator==(const __unconstrained_reverse_iterator& __lhs, const __unconstrained_reverse_iterator& __rhs) {
454 : return __lhs.base() == __rhs.base();
455 : }
456 :
457 : _LIBCPP_HIDE_FROM_ABI friend constexpr bool
458 : operator!=(const __unconstrained_reverse_iterator& __lhs, const __unconstrained_reverse_iterator& __rhs) {
459 : return __lhs.base() != __rhs.base();
460 : }
461 :
462 : _LIBCPP_HIDE_FROM_ABI friend constexpr bool
463 : operator<(const __unconstrained_reverse_iterator& __lhs, const __unconstrained_reverse_iterator& __rhs) {
464 : return __lhs.base() > __rhs.base();
465 : }
466 :
467 : _LIBCPP_HIDE_FROM_ABI friend constexpr bool
468 : operator>(const __unconstrained_reverse_iterator& __lhs, const __unconstrained_reverse_iterator& __rhs) {
469 : return __lhs.base() < __rhs.base();
470 : }
471 :
472 : _LIBCPP_HIDE_FROM_ABI friend constexpr bool
473 : operator<=(const __unconstrained_reverse_iterator& __lhs, const __unconstrained_reverse_iterator& __rhs) {
474 : return __lhs.base() >= __rhs.base();
475 : }
476 :
477 : _LIBCPP_HIDE_FROM_ABI friend constexpr bool
478 : operator>=(const __unconstrained_reverse_iterator& __lhs, const __unconstrained_reverse_iterator& __rhs) {
479 : return __lhs.base() <= __rhs.base();
480 : }
481 : };
482 :
483 : #endif // _LIBCPP_STD_VER <= 17
484 :
485 : template <template <class> class _RevIter1, template <class> class _RevIter2, class _Iter>
486 : struct __unwrap_reverse_iter_impl {
487 : using _UnwrappedIter = decltype(__unwrap_iter_impl<_Iter>::__unwrap(std::declval<_Iter>()));
488 : using _ReverseWrapper = _RevIter1<_RevIter2<_Iter> >;
489 :
490 : static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ReverseWrapper
491 : __rewrap(_ReverseWrapper __orig_iter, _UnwrappedIter __unwrapped_iter) {
492 : return _ReverseWrapper(
493 : _RevIter2<_Iter>(__unwrap_iter_impl<_Iter>::__rewrap(__orig_iter.base().base(), __unwrapped_iter)));
494 : }
495 :
496 : static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _UnwrappedIter __unwrap(_ReverseWrapper __i) _NOEXCEPT {
497 : return __unwrap_iter_impl<_Iter>::__unwrap(__i.base().base());
498 : }
499 : };
500 :
501 : #if _LIBCPP_STD_VER > 17
502 : template <ranges::bidirectional_range _Range>
503 : _LIBCPP_HIDE_FROM_ABI constexpr ranges::
504 : subrange<reverse_iterator<ranges::iterator_t<_Range>>, reverse_iterator<ranges::iterator_t<_Range>>>
505 : __reverse_range(_Range&& __range) {
506 : auto __first = ranges::begin(__range);
507 : return {std::make_reverse_iterator(ranges::next(__first, ranges::end(__range))), std::make_reverse_iterator(__first)};
508 : }
509 : #endif
510 :
511 : template <class _Iter, bool __b>
512 : struct __unwrap_iter_impl<reverse_iterator<reverse_iterator<_Iter> >, __b>
513 : : __unwrap_reverse_iter_impl<reverse_iterator, reverse_iterator, _Iter> {};
514 :
515 : #if _LIBCPP_STD_VER > 17
516 :
517 : template <class _Iter, bool __b>
518 : struct __unwrap_iter_impl<reverse_iterator<__unconstrained_reverse_iterator<_Iter>>, __b>
519 : : __unwrap_reverse_iter_impl<reverse_iterator, __unconstrained_reverse_iterator, _Iter> {};
520 :
521 : template <class _Iter, bool __b>
522 : struct __unwrap_iter_impl<__unconstrained_reverse_iterator<reverse_iterator<_Iter>>, __b>
523 : : __unwrap_reverse_iter_impl<__unconstrained_reverse_iterator, reverse_iterator, _Iter> {};
524 :
525 : template <class _Iter, bool __b>
526 : struct __unwrap_iter_impl<__unconstrained_reverse_iterator<__unconstrained_reverse_iterator<_Iter>>, __b>
527 : : __unwrap_reverse_iter_impl<__unconstrained_reverse_iterator, __unconstrained_reverse_iterator, _Iter> {};
528 :
529 : #endif // _LIBCPP_STD_VER > 17
530 :
531 : _LIBCPP_END_NAMESPACE_STD
532 :
533 : #endif // _LIBCPP___ITERATOR_REVERSE_ITERATOR_H
|