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 Generator>
14 // void generate(ExecutionPolicy&& exec,
15 // ForwardIterator first, ForwardIterator last,
22 #include "test_iterators.h"
23 #include "test_execution_policies.h"
24 #include "type_algorithms.h"
28 template <class ExecutionPolicy
>
29 void operator()(ExecutionPolicy
&& policy
) {
32 std::generate(policy
, Iter(std::begin(a
)), Iter(std::end(a
)), []() { return 1; });
33 assert(std::all_of(std::begin(a
), std::end(a
), [](int i
) { return i
== 1; }));
35 { // empty range works
37 std::generate(policy
, Iter(std::begin(a
)), Iter(std::begin(a
)), []() { return 1; });
40 { // single-element range works
42 std::generate(policy
, Iter(std::begin(a
)), Iter(std::end(a
)), []() { return 5; });
45 { // large range works
46 std::vector
<int> vec(150, 4);
47 std::generate(policy
, Iter(std::data(vec
)), Iter(std::data(vec
) + std::size(vec
)), []() { return 5; });
48 assert(std::all_of(std::begin(vec
), std::end(vec
), [](int i
) { return i
== 5; }));
53 int main(int, char**) {
54 types::for_each(types::forward_iterator_list
<int*>{}, TestIteratorWithPolicies
<Test
>{});