Back to home page

EIC code displayed by LXR

 
 

    


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

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___CXX03___ALGORITHM_COPY_H
0010 #define _LIBCPP___CXX03___ALGORITHM_COPY_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/__utility/move.h>
0020 #include <__cxx03/__utility/pair.h>
0021 
0022 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0023 #  pragma GCC system_header
0024 #endif
0025 
0026 _LIBCPP_PUSH_MACROS
0027 #include <__cxx03/__undef_macros>
0028 
0029 _LIBCPP_BEGIN_NAMESPACE_STD
0030 
0031 template <class, class _InIter, class _Sent, class _OutIter>
0032 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> __copy(_InIter, _Sent, _OutIter);
0033 
0034 template <class _AlgPolicy>
0035 struct __copy_impl {
0036   template <class _InIter, class _Sent, class _OutIter>
0037   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
0038   operator()(_InIter __first, _Sent __last, _OutIter __result) const {
0039     while (__first != __last) {
0040       *__result = *__first;
0041       ++__first;
0042       ++__result;
0043     }
0044 
0045     return std::make_pair(std::move(__first), std::move(__result));
0046   }
0047 
0048   template <class _InIter, class _OutIter>
0049   struct _CopySegment {
0050     using _Traits = __segmented_iterator_traits<_InIter>;
0051 
0052     _OutIter& __result_;
0053 
0054     _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit _CopySegment(_OutIter& __result)
0055         : __result_(__result) {}
0056 
0057     _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
0058     operator()(typename _Traits::__local_iterator __lfirst, typename _Traits::__local_iterator __llast) {
0059       __result_ = std::__copy<_AlgPolicy>(__lfirst, __llast, std::move(__result_)).second;
0060     }
0061   };
0062 
0063   template <class _InIter, class _OutIter, __enable_if_t<__is_segmented_iterator<_InIter>::value, int> = 0>
0064   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
0065   operator()(_InIter __first, _InIter __last, _OutIter __result) const {
0066     std::__for_each_segment(__first, __last, _CopySegment<_InIter, _OutIter>(__result));
0067     return std::make_pair(__last, std::move(__result));
0068   }
0069 
0070   template <class _InIter,
0071             class _OutIter,
0072             __enable_if_t<__has_random_access_iterator_category<_InIter>::value &&
0073                               !__is_segmented_iterator<_InIter>::value && __is_segmented_iterator<_OutIter>::value,
0074                           int> = 0>
0075   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
0076   operator()(_InIter __first, _InIter __last, _OutIter __result) const {
0077     using _Traits = __segmented_iterator_traits<_OutIter>;
0078     using _DiffT  = typename common_type<__iter_diff_t<_InIter>, __iter_diff_t<_OutIter> >::type;
0079 
0080     if (__first == __last)
0081       return std::make_pair(std::move(__first), std::move(__result));
0082 
0083     auto __local_first      = _Traits::__local(__result);
0084     auto __segment_iterator = _Traits::__segment(__result);
0085     while (true) {
0086       auto __local_last = _Traits::__end(__segment_iterator);
0087       auto __size       = std::min<_DiffT>(__local_last - __local_first, __last - __first);
0088       auto __iters      = std::__copy<_AlgPolicy>(__first, __first + __size, __local_first);
0089       __first           = std::move(__iters.first);
0090 
0091       if (__first == __last)
0092         return std::make_pair(std::move(__first), _Traits::__compose(__segment_iterator, std::move(__iters.second)));
0093 
0094       __local_first = _Traits::__begin(++__segment_iterator);
0095     }
0096   }
0097 
0098   // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer.
0099   template <class _In, class _Out, __enable_if_t<__can_lower_copy_assignment_to_memmove<_In, _Out>::value, int> = 0>
0100   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
0101   operator()(_In* __first, _In* __last, _Out* __result) const {
0102     return std::__copy_trivial_impl(__first, __last, __result);
0103   }
0104 };
0105 
0106 template <class _AlgPolicy, class _InIter, class _Sent, class _OutIter>
0107 pair<_InIter, _OutIter> inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
0108 __copy(_InIter __first, _Sent __last, _OutIter __result) {
0109   return std::__copy_move_unwrap_iters<__copy_impl<_AlgPolicy> >(
0110       std::move(__first), std::move(__last), std::move(__result));
0111 }
0112 
0113 template <class _InputIterator, class _OutputIterator>
0114 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
0115 copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
0116   return std::__copy<_ClassicAlgPolicy>(__first, __last, __result).second;
0117 }
0118 
0119 _LIBCPP_END_NAMESPACE_STD
0120 
0121 _LIBCPP_POP_MACROS
0122 
0123 #endif // _LIBCPP___CXX03___ALGORITHM_COPY_H