xref: /freebsd-src/contrib/llvm-project/libcxx/include/__algorithm/ranges_rotate.h (revision b3edf4467982447620505a28fc82e38a414c07dc)
161cfbce3SDimitry Andric //===----------------------------------------------------------------------===//
261cfbce3SDimitry Andric //
361cfbce3SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
461cfbce3SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
561cfbce3SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
661cfbce3SDimitry Andric //
761cfbce3SDimitry Andric //===----------------------------------------------------------------------===//
861cfbce3SDimitry Andric 
961cfbce3SDimitry Andric #ifndef _LIBCPP___ALGORITHM_RANGES_ROTATE_H
1061cfbce3SDimitry Andric #define _LIBCPP___ALGORITHM_RANGES_ROTATE_H
1161cfbce3SDimitry Andric 
1261cfbce3SDimitry Andric #include <__algorithm/iterator_operations.h>
1361cfbce3SDimitry Andric #include <__algorithm/ranges_iterator_concept.h>
1461cfbce3SDimitry Andric #include <__algorithm/rotate.h>
1561cfbce3SDimitry Andric #include <__config>
1661cfbce3SDimitry Andric #include <__iterator/concepts.h>
1761cfbce3SDimitry Andric #include <__iterator/iterator_traits.h>
1861cfbce3SDimitry Andric #include <__iterator/permutable.h>
1961cfbce3SDimitry Andric #include <__ranges/access.h>
2061cfbce3SDimitry Andric #include <__ranges/concepts.h>
2161cfbce3SDimitry Andric #include <__ranges/subrange.h>
2261cfbce3SDimitry Andric #include <__utility/move.h>
2361cfbce3SDimitry Andric 
2461cfbce3SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2561cfbce3SDimitry Andric #  pragma GCC system_header
2661cfbce3SDimitry Andric #endif
2761cfbce3SDimitry Andric 
28*b3edf446SDimitry Andric _LIBCPP_PUSH_MACROS
29*b3edf446SDimitry Andric #include <__undef_macros>
30*b3edf446SDimitry Andric 
3106c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 20
3261cfbce3SDimitry Andric 
3361cfbce3SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
3461cfbce3SDimitry Andric 
3561cfbce3SDimitry Andric namespace ranges {
3661cfbce3SDimitry Andric namespace __rotate {
3761cfbce3SDimitry Andric 
3861cfbce3SDimitry Andric struct __fn {
3961cfbce3SDimitry Andric   template <class _Iter, class _Sent>
__rotate_fn_impl__fn4006c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI constexpr static subrange<_Iter> __rotate_fn_impl(_Iter __first, _Iter __middle, _Sent __last) {
4106c3fb27SDimitry Andric     auto __ret = std::__rotate<_RangeAlgPolicy>(std::move(__first), std::move(__middle), std::move(__last));
4261cfbce3SDimitry Andric     return {std::move(__ret.first), std::move(__ret.second)};
4361cfbce3SDimitry Andric   }
4461cfbce3SDimitry Andric 
4561cfbce3SDimitry Andric   template <permutable _Iter, sentinel_for<_Iter> _Sent>
operator__fn4606c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> operator()(_Iter __first, _Iter __middle, _Sent __last) const {
4761cfbce3SDimitry Andric     return __rotate_fn_impl(std::move(__first), std::move(__middle), std::move(__last));
4861cfbce3SDimitry Andric   }
4961cfbce3SDimitry Andric 
5061cfbce3SDimitry Andric   template <forward_range _Range>
5161cfbce3SDimitry Andric     requires permutable<iterator_t<_Range>>
5206c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range>
operator__fn5306c3fb27SDimitry Andric   operator()(_Range&& __range, iterator_t<_Range> __middle) const {
5461cfbce3SDimitry Andric     return __rotate_fn_impl(ranges::begin(__range), std::move(__middle), ranges::end(__range));
5561cfbce3SDimitry Andric   }
5661cfbce3SDimitry Andric };
5761cfbce3SDimitry Andric 
5861cfbce3SDimitry Andric } // namespace __rotate
5961cfbce3SDimitry Andric 
6061cfbce3SDimitry Andric inline namespace __cpo {
6161cfbce3SDimitry Andric inline constexpr auto rotate = __rotate::__fn{};
6261cfbce3SDimitry Andric } // namespace __cpo
6361cfbce3SDimitry Andric } // namespace ranges
6461cfbce3SDimitry Andric 
6561cfbce3SDimitry Andric _LIBCPP_END_NAMESPACE_STD
6661cfbce3SDimitry Andric 
6706c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 20
6861cfbce3SDimitry Andric 
69*b3edf446SDimitry Andric _LIBCPP_POP_MACROS
70*b3edf446SDimitry Andric 
7161cfbce3SDimitry Andric #endif // _LIBCPP___ALGORITHM_RANGES_ROTATE_H
72