File indexing completed on 2026-05-03 08:13:18
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___CXX03___ALGORITHM_MOVE_H
0010 #define _LIBCPP___CXX03___ALGORITHM_MOVE_H
0011
0012 #include <__cxx03/__algorithm/copy_move_common.h>
0013 #include <__cxx03/__algorithm/for_each_segment.h>
0014 #include <__cxx03/__algorithm/iterator_operations.h>
0015 #include <__cxx03/__algorithm/min.h>
0016 #include <__cxx03/__config>
0017 #include <__cxx03/__iterator/segmented_iterator.h>
0018 #include <__cxx03/__type_traits/common_type.h>
0019 #include <__cxx03/__type_traits/is_constructible.h>
0020 #include <__cxx03/__utility/move.h>
0021 #include <__cxx03/__utility/pair.h>
0022
0023 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0024 # pragma GCC system_header
0025 #endif
0026
0027 _LIBCPP_PUSH_MACROS
0028 #include <__cxx03/__undef_macros>
0029
0030 _LIBCPP_BEGIN_NAMESPACE_STD
0031
0032 template <class _AlgPolicy, class _InIter, class _Sent, class _OutIter>
0033 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
0034 __move(_InIter __first, _Sent __last, _OutIter __result);
0035
0036 template <class _AlgPolicy>
0037 struct __move_impl {
0038 template <class _InIter, class _Sent, class _OutIter>
0039 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
0040 operator()(_InIter __first, _Sent __last, _OutIter __result) const {
0041 while (__first != __last) {
0042 *__result = _IterOps<_AlgPolicy>::__iter_move(__first);
0043 ++__first;
0044 ++__result;
0045 }
0046 return std::make_pair(std::move(__first), std::move(__result));
0047 }
0048
0049 template <class _InIter, class _OutIter>
0050 struct _MoveSegment {
0051 using _Traits = __segmented_iterator_traits<_InIter>;
0052
0053 _OutIter& __result_;
0054
0055 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit _MoveSegment(_OutIter& __result)
0056 : __result_(__result) {}
0057
0058 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
0059 operator()(typename _Traits::__local_iterator __lfirst, typename _Traits::__local_iterator __llast) {
0060 __result_ = std::__move<_AlgPolicy>(__lfirst, __llast, std::move(__result_)).second;
0061 }
0062 };
0063
0064 template <class _InIter, class _OutIter, __enable_if_t<__is_segmented_iterator<_InIter>::value, int> = 0>
0065 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
0066 operator()(_InIter __first, _InIter __last, _OutIter __result) const {
0067 std::__for_each_segment(__first, __last, _MoveSegment<_InIter, _OutIter>(__result));
0068 return std::make_pair(__last, std::move(__result));
0069 }
0070
0071 template <class _InIter,
0072 class _OutIter,
0073 __enable_if_t<__has_random_access_iterator_category<_InIter>::value &&
0074 !__is_segmented_iterator<_InIter>::value && __is_segmented_iterator<_OutIter>::value,
0075 int> = 0>
0076 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
0077 operator()(_InIter __first, _InIter __last, _OutIter __result) const {
0078 using _Traits = __segmented_iterator_traits<_OutIter>;
0079 using _DiffT = typename common_type<__iter_diff_t<_InIter>, __iter_diff_t<_OutIter> >::type;
0080
0081 if (__first == __last)
0082 return std::make_pair(std::move(__first), std::move(__result));
0083
0084 auto __local_first = _Traits::__local(__result);
0085 auto __segment_iterator = _Traits::__segment(__result);
0086 while (true) {
0087 auto __local_last = _Traits::__end(__segment_iterator);
0088 auto __size = std::min<_DiffT>(__local_last - __local_first, __last - __first);
0089 auto __iters = std::__move<_AlgPolicy>(__first, __first + __size, __local_first);
0090 __first = std::move(__iters.first);
0091
0092 if (__first == __last)
0093 return std::make_pair(std::move(__first), _Traits::__compose(__segment_iterator, std::move(__iters.second)));
0094
0095 __local_first = _Traits::__begin(++__segment_iterator);
0096 }
0097 }
0098
0099
0100 template <class _In, class _Out, __enable_if_t<__can_lower_move_assignment_to_memmove<_In, _Out>::value, int> = 0>
0101 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
0102 operator()(_In* __first, _In* __last, _Out* __result) const {
0103 return std::__copy_trivial_impl(__first, __last, __result);
0104 }
0105 };
0106
0107 template <class _AlgPolicy, class _InIter, class _Sent, class _OutIter>
0108 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
0109 __move(_InIter __first, _Sent __last, _OutIter __result) {
0110 return std::__copy_move_unwrap_iters<__move_impl<_AlgPolicy> >(
0111 std::move(__first), std::move(__last), std::move(__result));
0112 }
0113
0114 template <class _InputIterator, class _OutputIterator>
0115 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
0116 move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
0117 static_assert(is_copy_constructible<_InputIterator>::value, "Iterators has to be copy constructible.");
0118 static_assert(is_copy_constructible<_OutputIterator>::value, "The output iterator has to be copy constructible.");
0119
0120 return std::__move<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).second;
0121 }
0122
0123 _LIBCPP_END_NAMESPACE_STD
0124
0125 _LIBCPP_POP_MACROS
0126
0127 #endif