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_MOVE_COMMON_H
0010 #define _LIBCPP___CXX03___ALGORITHM_COPY_MOVE_COMMON_H
0011 
0012 #include <__cxx03/__algorithm/iterator_operations.h>
0013 #include <__cxx03/__algorithm/unwrap_iter.h>
0014 #include <__cxx03/__algorithm/unwrap_range.h>
0015 #include <__cxx03/__config>
0016 #include <__cxx03/__iterator/iterator_traits.h>
0017 #include <__cxx03/__memory/pointer_traits.h>
0018 #include <__cxx03/__string/constexpr_c_functions.h>
0019 #include <__cxx03/__type_traits/enable_if.h>
0020 #include <__cxx03/__type_traits/is_always_bitcastable.h>
0021 #include <__cxx03/__type_traits/is_constant_evaluated.h>
0022 #include <__cxx03/__type_traits/is_constructible.h>
0023 #include <__cxx03/__type_traits/is_trivially_assignable.h>
0024 #include <__cxx03/__type_traits/is_volatile.h>
0025 #include <__cxx03/__utility/move.h>
0026 #include <__cxx03/__utility/pair.h>
0027 #include <__cxx03/cstddef>
0028 
0029 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0030 #  pragma GCC system_header
0031 #endif
0032 
0033 _LIBCPP_PUSH_MACROS
0034 #include <__cxx03/__undef_macros>
0035 
0036 _LIBCPP_BEGIN_NAMESPACE_STD
0037 
0038 // Type traits.
0039 
0040 template <class _From, class _To>
0041 struct __can_lower_copy_assignment_to_memmove {
0042   static const bool value =
0043       // If the types are always bitcastable, it's valid to do a bitwise copy between them.
0044       __is_always_bitcastable<_From, _To>::value &&
0045       // Reject conversions that wouldn't be performed by the regular built-in assignment (e.g. between arrays).
0046       is_trivially_assignable<_To&, const _From&>::value &&
0047       // `memmove` doesn't accept `volatile` pointers, make sure the optimization SFINAEs away in that case.
0048       !is_volatile<_From>::value && !is_volatile<_To>::value;
0049 };
0050 
0051 template <class _From, class _To>
0052 struct __can_lower_move_assignment_to_memmove {
0053   static const bool value =
0054       __is_always_bitcastable<_From, _To>::value && is_trivially_assignable<_To&, _From&&>::value &&
0055       !is_volatile<_From>::value && !is_volatile<_To>::value;
0056 };
0057 
0058 // `memmove` algorithms implementation.
0059 
0060 template <class _In, class _Out>
0061 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
0062 __copy_trivial_impl(_In* __first, _In* __last, _Out* __result) {
0063   const size_t __n = static_cast<size_t>(__last - __first);
0064 
0065   std::__constexpr_memmove(__result, __first, __element_count(__n));
0066 
0067   return std::make_pair(__last, __result + __n);
0068 }
0069 
0070 template <class _In, class _Out>
0071 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_In*, _Out*>
0072 __copy_backward_trivial_impl(_In* __first, _In* __last, _Out* __result) {
0073   const size_t __n = static_cast<size_t>(__last - __first);
0074   __result -= __n;
0075 
0076   std::__constexpr_memmove(__result, __first, __element_count(__n));
0077 
0078   return std::make_pair(__last, __result);
0079 }
0080 
0081 // Iterator unwrapping and dispatching to the correct overload.
0082 
0083 template <class _InIter, class _OutIter>
0084 struct __can_rewrap
0085     : integral_constant<bool, is_copy_constructible<_InIter>::value && is_copy_constructible<_OutIter>::value> {};
0086 
0087 template <class _Algorithm,
0088           class _InIter,
0089           class _Sent,
0090           class _OutIter,
0091           __enable_if_t<__can_rewrap<_InIter, _OutIter>::value, int> = 0>
0092 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 pair<_InIter, _OutIter>
0093 __copy_move_unwrap_iters(_InIter __first, _Sent __last, _OutIter __out_first) {
0094   auto __range  = std::__unwrap_range(__first, std::move(__last));
0095   auto __result = _Algorithm()(std::move(__range.first), std::move(__range.second), std::__unwrap_iter(__out_first));
0096   return std::make_pair(std::__rewrap_range<_Sent>(std::move(__first), std::move(__result.first)),
0097                         std::__rewrap_iter(std::move(__out_first), std::move(__result.second)));
0098 }
0099 
0100 template <class _Algorithm,
0101           class _InIter,
0102           class _Sent,
0103           class _OutIter,
0104           __enable_if_t<!__can_rewrap<_InIter, _OutIter>::value, int> = 0>
0105 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 pair<_InIter, _OutIter>
0106 __copy_move_unwrap_iters(_InIter __first, _Sent __last, _OutIter __out_first) {
0107   return _Algorithm()(std::move(__first), std::move(__last), std::move(__out_first));
0108 }
0109 
0110 _LIBCPP_END_NAMESPACE_STD
0111 
0112 _LIBCPP_POP_MACROS
0113 
0114 #endif // _LIBCPP___CXX03___ALGORITHM_COPY_MOVE_COMMON_H