Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:11

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___ALGORITHM_RANGES_REVERSE_H
0010 #define _LIBCPP___ALGORITHM_RANGES_REVERSE_H
0011 
0012 #include <__config>
0013 #include <__iterator/concepts.h>
0014 #include <__iterator/iter_swap.h>
0015 #include <__iterator/next.h>
0016 #include <__iterator/permutable.h>
0017 #include <__ranges/access.h>
0018 #include <__ranges/concepts.h>
0019 #include <__ranges/dangling.h>
0020 
0021 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0022 #  pragma GCC system_header
0023 #endif
0024 
0025 #if _LIBCPP_STD_VER >= 20
0026 
0027 _LIBCPP_BEGIN_NAMESPACE_STD
0028 
0029 namespace ranges {
0030 struct __reverse {
0031   template <bidirectional_iterator _Iter, sentinel_for<_Iter> _Sent>
0032     requires permutable<_Iter>
0033   _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last) const {
0034     if constexpr (random_access_iterator<_Iter>) {
0035       if (__first == __last)
0036         return __first;
0037 
0038       auto __end = ranges::next(__first, __last);
0039       auto __ret = __end;
0040 
0041       while (__first < --__end) {
0042         ranges::iter_swap(__first, __end);
0043         ++__first;
0044       }
0045       return __ret;
0046     } else {
0047       auto __end = ranges::next(__first, __last);
0048       auto __ret = __end;
0049 
0050       while (__first != __end) {
0051         if (__first == --__end)
0052           break;
0053 
0054         ranges::iter_swap(__first, __end);
0055         ++__first;
0056       }
0057       return __ret;
0058     }
0059   }
0060 
0061   template <bidirectional_range _Range>
0062     requires permutable<iterator_t<_Range>>
0063   _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> operator()(_Range&& __range) const {
0064     return (*this)(ranges::begin(__range), ranges::end(__range));
0065   }
0066 };
0067 
0068 inline namespace __cpo {
0069 inline constexpr auto reverse = __reverse{};
0070 } // namespace __cpo
0071 } // namespace ranges
0072 
0073 _LIBCPP_END_NAMESPACE_STD
0074 
0075 #endif // _LIBCPP_STD_VER >= 20
0076 
0077 #endif // _LIBCPP___ALGORITHM_RANGES_REVERSE_H