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_SHIFT_LEFT_H
10#define _LIBCPP___ALGORITHM_RANGES_SHIFT_LEFT_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/shift_left.h>
14#include <__config>
15#include <__iterator/concepts.h>
16#include <__iterator/distance.h>
17#include <__iterator/incrementable_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_LIBCPP_BEGIN_NAMESPACE_STD
32
33#if _LIBCPP_STD_VER >= 23
34
35namespace ranges {
36namespace __shift_left {
37
38struct __fn {
39 template <permutable _Iter, sentinel_for<_Iter> _Sent>
40 _LIBCPP_HIDE_FROM_ABI static constexpr subrange<_Iter>
41 operator()(_Iter __first, _Sent __last, iter_difference_t<_Iter> __n) {
42 auto __ret = std::__shift_left<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__n));
43 return {std::move(__ret.first), std::move(__ret.second)};
44 }
45
46 template <forward_range _Range>
47 requires permutable<iterator_t<_Range>>
48 _LIBCPP_HIDE_FROM_ABI static constexpr borrowed_subrange_t<_Range>
49 operator()(_Range&& __range, range_difference_t<_Range> __n) {
50 if constexpr (sized_range<_Range>) {
51 if (__n >= ranges::distance(__range)) {
52 return {ranges::begin(__range), ranges::begin(__range)};
53 }
54 }
55
56 auto __ret = std::__shift_left<_RangeAlgPolicy>(ranges::begin(__range), ranges::end(__range), std::move(__n));
57 return {std::move(__ret.first), std::move(__ret.second)};
58 }
59};
60} // namespace __shift_left
61
62inline namespace __cpo {
63inline constexpr auto shift_left = __shift_left::__fn{};
64} // namespace __cpo
65} // namespace ranges
66
67#endif // _LIBCPP_STD_VER >= 23
68
69_LIBCPP_END_NAMESPACE_STD
70
71_LIBCPP_POP_MACROS
72
73#endif // _LIBCPP___ALGORITHM_RANGES_SHIFT_LEFT_H
74