aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/libcxx/include/__algorithm/copy_backward.h
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2022-07-27 20:11:54 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-02-08 19:04:48 +0000
commit972a253a57b6f144b0e4a3e2080a2a0076ec55a0 (patch)
treea8aeeb0997a0a52500f1fa0644244206cf71df94 /contrib/llvm-project/libcxx/include/__algorithm/copy_backward.h
parentfcaf7f8644a9988098ac6be2165bce3ea4786e91 (diff)
parent08e8dd7b9db7bb4a9de26d44c1cbfd24e869c014 (diff)
Diffstat (limited to 'contrib/llvm-project/libcxx/include/__algorithm/copy_backward.h')
-rw-r--r--contrib/llvm-project/libcxx/include/__algorithm/copy_backward.h42
1 files changed, 25 insertions, 17 deletions
diff --git a/contrib/llvm-project/libcxx/include/__algorithm/copy_backward.h b/contrib/llvm-project/libcxx/include/__algorithm/copy_backward.h
index dd43a91ffa87..26b8c4d791fd 100644
--- a/contrib/llvm-project/libcxx/include/__algorithm/copy_backward.h
+++ b/contrib/llvm-project/libcxx/include/__algorithm/copy_backward.h
@@ -10,10 +10,16 @@
#define _LIBCPP___ALGORITHM_COPY_BACKWARD_H
#include <__algorithm/copy.h>
+#include <__algorithm/iterator_operations.h>
+#include <__algorithm/ranges_copy.h>
#include <__algorithm/unwrap_iter.h>
+#include <__concepts/same_as.h>
#include <__config>
#include <__iterator/iterator_traits.h>
#include <__iterator/reverse_iterator.h>
+#include <__ranges/subrange.h>
+#include <__utility/move.h>
+#include <__utility/pair.h>
#include <cstring>
#include <type_traits>
@@ -23,29 +29,31 @@
_LIBCPP_BEGIN_NAMESPACE_STD
-template <class _Iter1, class _Sent1, class _Iter2>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
-pair<_Iter1, _Iter2> __copy_backward_impl(_Iter1 __first, _Sent1 __last, _Iter2 __result) {
- auto __ret = std::__copy(reverse_iterator<_Iter1>(__last),
- reverse_iterator<_Sent1>(__first),
- reverse_iterator<_Iter2>(__result));
- return pair<_Iter1, _Iter2>(__ret.first.base(), __ret.second.base());
+template <class _AlgPolicy, class _InputIterator, class _OutputIterator,
+ __enable_if_t<is_same<_AlgPolicy, _ClassicAlgPolicy>::value, int> = 0>
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 pair<_InputIterator, _OutputIterator>
+__copy_backward(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
+ auto __ret = std::__copy(
+ __unconstrained_reverse_iterator<_InputIterator>(__last),
+ __unconstrained_reverse_iterator<_InputIterator>(__first),
+ __unconstrained_reverse_iterator<_OutputIterator>(__result));
+ return pair<_InputIterator, _OutputIterator>(__ret.first.base(), __ret.second.base());
}
-template <class _Iter1, class _Sent1, class _Iter2>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
-pair<_Iter1, _Iter2> __copy_backward(_Iter1 __first, _Sent1 __last, _Iter2 __result) {
- auto __ret = std::__copy_backward_impl(std::__unwrap_iter(__first),
- std::__unwrap_iter(__last),
- std::__unwrap_iter(__result));
- return pair<_Iter1, _Iter2>(std::__rewrap_iter(__first, __ret.first), std::__rewrap_iter(__result, __ret.second));
+#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+template <class _AlgPolicy, class _Iter1, class _Sent1, class _Iter2,
+ __enable_if_t<is_same<_AlgPolicy, _RangeAlgPolicy>::value, int> = 0>
+_LIBCPP_HIDE_FROM_ABI constexpr pair<_Iter1, _Iter2> __copy_backward(_Iter1 __first, _Sent1 __last, _Iter2 __result) {
+ auto __reverse_range = std::__reverse_range(std::ranges::subrange(std::move(__first), std::move(__last)));
+ auto __ret = ranges::copy(std::move(__reverse_range), std::make_reverse_iterator(__result));
+ return std::make_pair(__ret.in.base(), __ret.out.base());
}
+#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
template <class _BidirectionalIterator1, class _BidirectionalIterator2>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
-_BidirectionalIterator2
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _BidirectionalIterator2
copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) {
- return std::__copy_backward(__first, __last, __result).second;
+ return std::__copy_backward<_ClassicAlgPolicy>(__first, __last, __result).second;
}
_LIBCPP_END_NAMESPACE_STD