pstl_fill.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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_FILL_H
  9. #define _LIBCPP___ALGORITHM_PSTL_FILL_H
  10. #include <__algorithm/fill_n.h>
  11. #include <__algorithm/pstl_for_each.h>
  12. #include <__algorithm/pstl_frontend_dispatch.h>
  13. #include <__config>
  14. #include <__iterator/concepts.h>
  15. #include <__iterator/cpp17_iterator_concepts.h>
  16. #include <__iterator/iterator_traits.h>
  17. #include <__type_traits/enable_if.h>
  18. #include <__type_traits/is_execution_policy.h>
  19. #include <__type_traits/remove_cvref.h>
  20. #include <__utility/move.h>
  21. #include <__utility/terminate_on_exception.h>
  22. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  23. # pragma GCC system_header
  24. #endif
  25. #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
  26. _LIBCPP_BEGIN_NAMESPACE_STD
  27. template <class>
  28. void __pstl_fill(); // declaration needed for the frontend dispatch below
  29. template <class _ExecutionPolicy,
  30. class _ForwardIterator,
  31. class _Tp,
  32. class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
  33. enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
  34. _LIBCPP_HIDE_FROM_ABI void
  35. fill(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
  36. _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
  37. std::__pstl_frontend_dispatch(
  38. _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_fill, _RawPolicy),
  39. [&](_ForwardIterator __g_first, _ForwardIterator __g_last, const _Tp& __g_value) {
  40. std::for_each(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __element) {
  41. __element = __g_value;
  42. });
  43. },
  44. std::move(__first),
  45. std::move(__last),
  46. __value);
  47. }
  48. template <class>
  49. void __pstl_fill_n(); // declaration needed for the frontend dispatch below
  50. template <class _ExecutionPolicy,
  51. class _ForwardIterator,
  52. class _SizeT,
  53. class _Tp,
  54. class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
  55. enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
  56. _LIBCPP_HIDE_FROM_ABI void
  57. fill_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _SizeT __n, const _Tp& __value) {
  58. _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
  59. std::__pstl_frontend_dispatch(
  60. _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_fill_n, _RawPolicy),
  61. [&](_ForwardIterator __g_first, _SizeT __g_n, const _Tp& __g_value) {
  62. if constexpr (__has_random_access_iterator_category_or_concept<_ForwardIterator>::value)
  63. std::fill(__policy, __g_first, __g_first + __g_n, __g_value);
  64. else
  65. std::fill_n(__g_first, __g_n, __g_value);
  66. },
  67. std::move(__first),
  68. __n,
  69. __value);
  70. }
  71. _LIBCPP_END_NAMESPACE_STD
  72. #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
  73. #endif // _LIBCPP___ALGORITHM_PSTL_FILL_H