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_GENERATE_H 10 #define _LIBCPP___ALGORITHM_PSTL_GENERATE_H 11 12 #include <__algorithm/pstl_backend.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 <__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 22 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 23 # pragma GCC system_header 24 #endif 25 26 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 27 28 _LIBCPP_BEGIN_NAMESPACE_STD 29 30 template <class> 31 void __pstl_generate(); 32 33 template <class _ExecutionPolicy, 34 class _ForwardIterator, 35 class _Generator, 36 class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, 37 enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> 38 _LIBCPP_HIDE_FROM_ABI void 39 generate(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Generator __gen) { 40 _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator); 41 std::__pstl_frontend_dispatch( 42 _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_generate), 43 [&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last, _Generator __g_gen) { 44 std::for_each( 45 __policy, std::move(__g_first), std::move(__g_last), [&](__iter_reference<_ForwardIterator> __element) { 46 __element = __g_gen(); 47 }); 48 }, 49 std::move(__first), 50 std::move(__last), 51 std::move(__gen)); 52 } 53 54 template <class> 55 void __pstl_generate_n(); 56 57 template <class _ExecutionPolicy, 58 class _ForwardIterator, 59 class _Size, 60 class _Generator, 61 class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, 62 enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> 63 _LIBCPP_HIDE_FROM_ABI void 64 generate_n(_ExecutionPolicy&& __policy, _ForwardIterator __first, _Size __n, _Generator __gen) { 65 _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator); 66 std::__pstl_frontend_dispatch( 67 _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_generate_n), 68 [&__policy](_ForwardIterator __g_first, _Size __g_n, _Generator __g_gen) { 69 std::for_each_n(__policy, std::move(__g_first), __g_n, [&](__iter_reference<_ForwardIterator> __element) { 70 __element = __g_gen(); 71 }); 72 }, 73 std::move(__first), 74 __n, 75 std::move(__gen)); 76 } 77 78 _LIBCPP_END_NAMESPACE_STD 79 80 #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 81 82 #endif // _LIBCPP___ALGORITHM_PSTL_GENERATE_H 83