ranges_rotate.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #ifndef _LIBCPP___ALGORITHM_RANGES_ROTATE_H
  9. #define _LIBCPP___ALGORITHM_RANGES_ROTATE_H
  10. #include <__algorithm/iterator_operations.h>
  11. #include <__algorithm/ranges_iterator_concept.h>
  12. #include <__algorithm/rotate.h>
  13. #include <__config>
  14. #include <__iterator/concepts.h>
  15. #include <__iterator/iterator_traits.h>
  16. #include <__iterator/permutable.h>
  17. #include <__ranges/access.h>
  18. #include <__ranges/concepts.h>
  19. #include <__ranges/subrange.h>
  20. #include <__utility/move.h>
  21. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  22. # pragma GCC system_header
  23. #endif
  24. #if _LIBCPP_STD_VER >= 20
  25. _LIBCPP_BEGIN_NAMESPACE_STD
  26. namespace ranges {
  27. namespace __rotate {
  28. struct __fn {
  29. template <class _Iter, class _Sent>
  30. _LIBCPP_HIDE_FROM_ABI constexpr static subrange<_Iter> __rotate_fn_impl(_Iter __first, _Iter __middle, _Sent __last) {
  31. auto __ret = std::__rotate<_RangeAlgPolicy>(std::move(__first), std::move(__middle), std::move(__last));
  32. return {std::move(__ret.first), std::move(__ret.second)};
  33. }
  34. template <permutable _Iter, sentinel_for<_Iter> _Sent>
  35. _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> operator()(_Iter __first, _Iter __middle, _Sent __last) const {
  36. return __rotate_fn_impl(std::move(__first), std::move(__middle), std::move(__last));
  37. }
  38. template <forward_range _Range>
  39. requires permutable<iterator_t<_Range>>
  40. _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range>
  41. operator()(_Range&& __range, iterator_t<_Range> __middle) const {
  42. return __rotate_fn_impl(ranges::begin(__range), std::move(__middle), ranges::end(__range));
  43. }
  44. };
  45. } // namespace __rotate
  46. inline namespace __cpo {
  47. inline constexpr auto rotate = __rotate::__fn{};
  48. } // namespace __cpo
  49. } // namespace ranges
  50. _LIBCPP_END_NAMESPACE_STD
  51. #endif // _LIBCPP_STD_VER >= 20
  52. #endif // _LIBCPP___ALGORITHM_RANGES_ROTATE_H