xref: /freebsd/contrib/llvm-project/libcxx/include/__algorithm/ranges_rotate.h (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
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 #ifndef _LIBCPP___ALGORITHM_RANGES_ROTATE_H
10 #define _LIBCPP___ALGORITHM_RANGES_ROTATE_H
11 
12 #include <__algorithm/iterator_operations.h>
13 #include <__algorithm/ranges_iterator_concept.h>
14 #include <__algorithm/rotate.h>
15 #include <__config>
16 #include <__iterator/concepts.h>
17 #include <__iterator/iterator_traits.h>
18 #include <__iterator/permutable.h>
19 #include <__ranges/access.h>
20 #include <__ranges/concepts.h>
21 #include <__ranges/subrange.h>
22 #include <__utility/move.h>
23 
24 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25 #  pragma GCC system_header
26 #endif
27 
28 _LIBCPP_PUSH_MACROS
29 #include <__undef_macros>
30 
31 #if _LIBCPP_STD_VER >= 20
32 
33 _LIBCPP_BEGIN_NAMESPACE_STD
34 
35 namespace ranges {
36 namespace __rotate {
37 
38 struct __fn {
39   template <class _Iter, class _Sent>
40   _LIBCPP_HIDE_FROM_ABI constexpr static subrange<_Iter> __rotate_fn_impl(_Iter __first, _Iter __middle, _Sent __last) {
41     auto __ret = std::__rotate<_RangeAlgPolicy>(std::move(__first), std::move(__middle), std::move(__last));
42     return {std::move(__ret.first), std::move(__ret.second)};
43   }
44 
45   template <permutable _Iter, sentinel_for<_Iter> _Sent>
46   _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> operator()(_Iter __first, _Iter __middle, _Sent __last) const {
47     return __rotate_fn_impl(std::move(__first), std::move(__middle), std::move(__last));
48   }
49 
50   template <forward_range _Range>
51     requires permutable<iterator_t<_Range>>
52   _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range>
53   operator()(_Range&& __range, iterator_t<_Range> __middle) const {
54     return __rotate_fn_impl(ranges::begin(__range), std::move(__middle), ranges::end(__range));
55   }
56 };
57 
58 } // namespace __rotate
59 
60 inline namespace __cpo {
61 inline constexpr auto rotate = __rotate::__fn{};
62 } // namespace __cpo
63 } // namespace ranges
64 
65 _LIBCPP_END_NAMESPACE_STD
66 
67 #endif // _LIBCPP_STD_VER >= 20
68 
69 _LIBCPP_POP_MACROS
70 
71 #endif // _LIBCPP___ALGORITHM_RANGES_ROTATE_H
72