1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
11 // UNSUPPORTED: libcpp-has-no-incomplete-pstl
13 // template<class ExecutionPolicy, class ForwardIterator, class Size, class Generator>
14 // ForwardIterator generate_n(ExecutionPolicy&& exec,
15 // ForwardIterator first, Size n, Generator gen);
21 #include "test_iterators.h"
22 #include "test_execution_policies.h"
23 #include "type_algorithms.h"
27 template <class ExecutionPolicy
>
28 void operator()(ExecutionPolicy
&& policy
) {
31 std::generate_n(policy
, Iter(std::begin(a
)), std::size(a
), []() { return 1; });
32 assert(std::all_of(std::begin(a
), std::end(a
), [](int i
) { return i
== 1; }));
34 { // empty range works
36 std::generate_n(policy
, Iter(std::begin(a
)), 0, []() { return 1; });
39 { // single-element range works
41 std::generate_n(policy
, Iter(std::begin(a
)), std::size(a
), []() { return 5; });
44 { // large range works
45 std::vector
<int> vec(150, 4);
46 std::generate_n(policy
, Iter(std::data(vec
)), std::size(vec
), []() { return 5; });
47 assert(std::all_of(std::begin(vec
), std::end(vec
), [](int i
) { return i
== 5; }));
52 int main(int, char**) {
53 types::for_each(types::forward_iterator_list
<int*>{}, TestIteratorWithPolicies
<Test
>{});