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 <__config>
13 #include <__algorithm/unwrap_iter.h>
14 #include <__utility/move.h>
15 #include <cstring>
16 #include <utility>
17 #include <type_traits>
18 
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 #pragma GCC system_header
21 #endif
22 
23 _LIBCPP_PUSH_MACROS
24 #include <__undef_macros>
25 
26 _LIBCPP_BEGIN_NAMESPACE_STD
27 
28 // move
29 
30 template <class _InputIterator, class _OutputIterator>
31 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
32 _OutputIterator
33 __move_constexpr(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
34 {
35     for (; __first != __last; ++__first, (void) ++__result)
36         *__result = _VSTD::move(*__first);
37     return __result;
38 }
39 
40 template <class _InputIterator, class _OutputIterator>
41 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
42 _OutputIterator
43 __move(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
44 {
45     return _VSTD::__move_constexpr(__first, __last, __result);
46 }
47 
48 template <class _Tp, class _Up>
49 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
50 typename enable_if
51 <
52     is_same<typename remove_const<_Tp>::type, _Up>::value &&
53     is_trivially_move_assignable<_Up>::value,
54     _Up*
55 >::type
56 __move(_Tp* __first, _Tp* __last, _Up* __result)
57 {
58     const size_t __n = static_cast<size_t>(__last - __first);
59     if (__n > 0)
60         _VSTD::memmove(__result, __first, __n * sizeof(_Up));
61     return __result + __n;
62 }
63 
64 template <class _InputIterator, class _OutputIterator>
65 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
66 _OutputIterator
67 move(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
68 {
69     if (__libcpp_is_constant_evaluated()) {
70         return _VSTD::__move_constexpr(__first, __last, __result);
71     } else {
72         return _VSTD::__rewrap_iter(__result,
73             _VSTD::__move(_VSTD::__unwrap_iter(__first),
74                           _VSTD::__unwrap_iter(__last),
75                           _VSTD::__unwrap_iter(__result)));
76     }
77 }
78 
79 _LIBCPP_END_NAMESPACE_STD
80 
81 _LIBCPP_POP_MACROS
82 
83 #endif // _LIBCPP___ALGORITHM_MOVE_H
84