xref: /llvm-project/libcxx/include/__algorithm/ranges_rotate.h (revision d10dc5a06fac4dcabf2264c64c8672c6f6ae36fb)
136c746caSKonstantin Varlamov //===----------------------------------------------------------------------===//
236c746caSKonstantin Varlamov //
336c746caSKonstantin Varlamov // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
436c746caSKonstantin Varlamov // See https://llvm.org/LICENSE.txt for license information.
536c746caSKonstantin Varlamov // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
636c746caSKonstantin Varlamov //
736c746caSKonstantin Varlamov //===----------------------------------------------------------------------===//
836c746caSKonstantin Varlamov 
936c746caSKonstantin Varlamov #ifndef _LIBCPP___ALGORITHM_RANGES_ROTATE_H
1036c746caSKonstantin Varlamov #define _LIBCPP___ALGORITHM_RANGES_ROTATE_H
1136c746caSKonstantin Varlamov 
1236c746caSKonstantin Varlamov #include <__algorithm/iterator_operations.h>
1336c746caSKonstantin Varlamov #include <__algorithm/ranges_iterator_concept.h>
1436c746caSKonstantin Varlamov #include <__algorithm/rotate.h>
1536c746caSKonstantin Varlamov #include <__config>
1636c746caSKonstantin Varlamov #include <__iterator/concepts.h>
1736c746caSKonstantin Varlamov #include <__iterator/iterator_traits.h>
1836c746caSKonstantin Varlamov #include <__iterator/permutable.h>
1936c746caSKonstantin Varlamov #include <__ranges/access.h>
2036c746caSKonstantin Varlamov #include <__ranges/concepts.h>
2136c746caSKonstantin Varlamov #include <__ranges/subrange.h>
2236c746caSKonstantin Varlamov #include <__utility/move.h>
2336c746caSKonstantin Varlamov 
2436c746caSKonstantin Varlamov #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2536c746caSKonstantin Varlamov #  pragma GCC system_header
2636c746caSKonstantin Varlamov #endif
2736c746caSKonstantin Varlamov 
287b462251SLouis Dionne _LIBCPP_PUSH_MACROS
297b462251SLouis Dionne #include <__undef_macros>
307b462251SLouis Dionne 
314f15267dSNikolas Klauser #if _LIBCPP_STD_VER >= 20
3236c746caSKonstantin Varlamov 
3336c746caSKonstantin Varlamov _LIBCPP_BEGIN_NAMESPACE_STD
3436c746caSKonstantin Varlamov 
3536c746caSKonstantin Varlamov namespace ranges {
36*d10dc5a0SChristopher Di Bella struct __rotate {
3736c746caSKonstantin Varlamov   template <class _Iter, class _Sent>
385aa03b64SLouis Dionne   _LIBCPP_HIDE_FROM_ABI constexpr static subrange<_Iter> __rotate_fn_impl(_Iter __first, _Iter __middle, _Sent __last) {
395aa03b64SLouis Dionne     auto __ret = std::__rotate<_RangeAlgPolicy>(std::move(__first), std::move(__middle), std::move(__last));
4036c746caSKonstantin Varlamov     return {std::move(__ret.first), std::move(__ret.second)};
4136c746caSKonstantin Varlamov   }
4236c746caSKonstantin Varlamov 
4336c746caSKonstantin Varlamov   template <permutable _Iter, sentinel_for<_Iter> _Sent>
445aa03b64SLouis Dionne   _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> operator()(_Iter __first, _Iter __middle, _Sent __last) const {
4536c746caSKonstantin Varlamov     return __rotate_fn_impl(std::move(__first), std::move(__middle), std::move(__last));
4636c746caSKonstantin Varlamov   }
4736c746caSKonstantin Varlamov 
4836c746caSKonstantin Varlamov   template <forward_range _Range>
4936c746caSKonstantin Varlamov     requires permutable<iterator_t<_Range>>
505aa03b64SLouis Dionne   _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range>
515aa03b64SLouis Dionne   operator()(_Range&& __range, iterator_t<_Range> __middle) const {
5236c746caSKonstantin Varlamov     return __rotate_fn_impl(ranges::begin(__range), std::move(__middle), ranges::end(__range));
5336c746caSKonstantin Varlamov   }
5436c746caSKonstantin Varlamov };
5536c746caSKonstantin Varlamov 
5636c746caSKonstantin Varlamov inline namespace __cpo {
57*d10dc5a0SChristopher Di Bella inline constexpr auto rotate = __rotate{};
5836c746caSKonstantin Varlamov } // namespace __cpo
5936c746caSKonstantin Varlamov } // namespace ranges
6036c746caSKonstantin Varlamov 
6136c746caSKonstantin Varlamov _LIBCPP_END_NAMESPACE_STD
6236c746caSKonstantin Varlamov 
634f15267dSNikolas Klauser #endif // _LIBCPP_STD_VER >= 20
6436c746caSKonstantin Varlamov 
657b462251SLouis Dionne _LIBCPP_POP_MACROS
667b462251SLouis Dionne 
6736c746caSKonstantin Varlamov #endif // _LIBCPP___ALGORITHM_RANGES_ROTATE_H
68