Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:08

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