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