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_MOVE_H 10 #define _LIBCPP___ALGORITHM_MOVE_H 11 12 #include <__algorithm/copy_move_common.h> 13 #include <__algorithm/iterator_operations.h> 14 #include <__config> 15 #include <__type_traits/is_copy_constructible.h> 16 #include <__utility/move.h> 17 #include <__utility/pair.h> 18 19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 20 # pragma GCC system_header 21 #endif 22 23 _LIBCPP_BEGIN_NAMESPACE_STD 24 25 template <class _AlgPolicy> 26 struct __move_loop { 27 template <class _InIter, class _Sent, class _OutIter> 28 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> 29 operator()(_InIter __first, _Sent __last, _OutIter __result) const { 30 while (__first != __last) { 31 *__result = _IterOps<_AlgPolicy>::__iter_move(__first); 32 ++__first; 33 ++__result; 34 } 35 return std::make_pair(std::move(__first), std::move(__result)); 36 } 37 }; 38 39 struct __move_trivial { 40 // At this point, the iterators have been unwrapped so any `contiguous_iterator` has been unwrapped to a pointer. 41 template <class _In, class _Out, 42 __enable_if_t<__can_lower_move_assignment_to_memmove<_In, _Out>::value, int> = 0> 43 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*> 44 operator()(_In* __first, _In* __last, _Out* __result) const { 45 return std::__copy_trivial_impl(__first, __last, __result); 46 } 47 }; 48 49 template <class _AlgPolicy, class _InIter, class _Sent, class _OutIter> 50 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 51 pair<_InIter, _OutIter> 52 __move(_InIter __first, _Sent __last, _OutIter __result) { 53 return std::__dispatch_copy_or_move<_AlgPolicy, __move_loop<_AlgPolicy>, __move_trivial>( 54 std::move(__first), std::move(__last), std::move(__result)); 55 } 56 57 template <class _InputIterator, class _OutputIterator> 58 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 59 _OutputIterator move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { 60 static_assert(is_copy_constructible<_InputIterator>::value, "Iterators has to be copy constructible."); 61 static_assert(is_copy_constructible<_OutputIterator>::value, "The output iterator has to be copy constructible."); 62 63 return std::__move<_ClassicAlgPolicy>( 64 std::move(__first), std::move(__last), std::move(__result)).second; 65 } 66 67 _LIBCPP_END_NAMESPACE_STD 68 69 #endif // _LIBCPP___ALGORITHM_MOVE_H 70