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