pstl_copy.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #ifndef _LIBCPP___ALGORITHM_PSTL_COPY_H
  9. #define _LIBCPP___ALGORITHM_PSTL_COPY_H
  10. #include <__algorithm/copy_n.h>
  11. #include <__algorithm/pstl_backend.h>
  12. #include <__algorithm/pstl_frontend_dispatch.h>
  13. #include <__algorithm/pstl_transform.h>
  14. #include <__config>
  15. #include <__functional/identity.h>
  16. #include <__iterator/concepts.h>
  17. #include <__type_traits/enable_if.h>
  18. #include <__type_traits/is_constant_evaluated.h>
  19. #include <__type_traits/is_execution_policy.h>
  20. #include <__type_traits/is_trivially_copyable.h>
  21. #include <__type_traits/remove_cvref.h>
  22. #include <__utility/move.h>
  23. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  24. # pragma GCC system_header
  25. #endif
  26. #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
  27. _LIBCPP_BEGIN_NAMESPACE_STD
  28. // TODO: Use the std::copy/move shenanigans to forward to std::memmove
  29. template <class>
  30. void __pstl_copy();
  31. template <class _ExecutionPolicy,
  32. class _ForwardIterator,
  33. class _ForwardOutIterator,
  34. class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
  35. enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
  36. _LIBCPP_HIDE_FROM_ABI _ForwardOutIterator
  37. copy(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _ForwardOutIterator __result) {
  38. return std::__pstl_frontend_dispatch(
  39. _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_copy, _RawPolicy),
  40. [&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last, _ForwardOutIterator __g_result) {
  41. return std::transform(__policy, __g_first, __g_last, __g_result, __identity());
  42. },
  43. std::move(__first),
  44. std::move(__last),
  45. std::move(__result));
  46. }
  47. template <class>
  48. void __pstl_copy_n();
  49. template <class _ExecutionPolicy,
  50. class _ForwardIterator,
  51. class _ForwardOutIterator,
  52. class _Size,
  53. class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
  54. enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
  55. _LIBCPP_HIDE_FROM_ABI _ForwardOutIterator
  56. copy_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __n, _ForwardOutIterator __result) {
  57. return std::__pstl_frontend_dispatch(
  58. _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_copy_n, _RawPolicy),
  59. [&__policy](_ForwardIterator __g_first, _Size __g_n, _ForwardOutIterator __g_result) {
  60. if constexpr (__has_random_access_iterator_category_or_concept<_ForwardIterator>::value)
  61. return std::copy(__policy, __g_first, __g_first + __g_n, __g_result);
  62. else
  63. return std::copy_n(__g_first, __g_n, __g_result);
  64. },
  65. std::move(__first),
  66. __n,
  67. std::move(__result));
  68. }
  69. _LIBCPP_END_NAMESPACE_STD
  70. #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
  71. #endif // _LIBCPP___ALGORITHM_PSTL_COPY_H