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_MOVE_BACKWARD_H
10 #define _LIBCPP___ALGORITHM_RANGES_MOVE_BACKWARD_H
11 
12 #include <__algorithm/in_out_result.h>
13 #include <__algorithm/ranges_move.h>
14 #include <__config>
15 #include <__iterator/concepts.h>
16 #include <__iterator/iter_move.h>
17 #include <__iterator/next.h>
18 #include <__iterator/reverse_iterator.h>
19 #include <__ranges/access.h>
20 #include <__ranges/concepts.h>
21 #include <__ranges/dangling.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 #if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
29 
30 _LIBCPP_BEGIN_NAMESPACE_STD
31 
32 namespace ranges {
33 
34 template <class _InIter, class _OutIter>
35 using move_backward_result = in_out_result<_InIter, _OutIter>;
36 
37 namespace __move_backward {
38 struct __fn {
39 
40   template <class _InIter, class _Sent, class _OutIter>
41   _LIBCPP_HIDE_FROM_ABI constexpr static
42   move_backward_result<_InIter, _OutIter> __move_backward_impl(_InIter __first, _Sent __last, _OutIter __result) {
43     auto __last_iter = ranges::next(__first, std::move(__last));
44     auto __ret = ranges::move(std::make_reverse_iterator(__last_iter),
45                               std::make_reverse_iterator(__first),
46                               std::make_reverse_iterator(__result));
47     return {std::move(__last_iter), std::move(__ret.out.base())};
48   }
49 
50   template <bidirectional_iterator _InIter, sentinel_for<_InIter> _Sent, bidirectional_iterator _OutIter>
51     requires indirectly_movable<_InIter, _OutIter>
52   _LIBCPP_HIDE_FROM_ABI constexpr
53   move_backward_result<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result) const {
54     return __move_backward_impl(std::move(__first), std::move(__last), std::move(__result));
55   }
56 
57   template <bidirectional_range _Range, bidirectional_iterator _Iter>
58     requires indirectly_movable<iterator_t<_Range>, _Iter>
59   _LIBCPP_HIDE_FROM_ABI constexpr
60   move_backward_result<borrowed_iterator_t<_Range>, _Iter> operator()(_Range&& __range, _Iter __result) const {
61     return __move_backward_impl(ranges::begin(__range), ranges::end(__range), std::move(__result));
62   }
63 
64 };
65 } // namespace __move_backward
66 
67 inline namespace __cpo {
68   inline constexpr auto move_backward = __move_backward::__fn{};
69 } // namespace __cpo
70 } // namespace ranges
71 
72 _LIBCPP_END_NAMESPACE_STD
73 
74 #endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
75 
76 #endif // _LIBCPP___ALGORITHM_RANGES_MOVE_BACKWARD_H
77