Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / algorithms / alg.modifying.operations / alg.generate / pstl.generate.pass.cpp
blob064b71091c325dea5c593736b0ec4aff9fcdfa9d
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 //===----------------------------------------------------------------------===//
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,
16 // Generator gen);
18 #include <algorithm>
19 #include <cassert>
20 #include <vector>
22 #include "test_iterators.h"
23 #include "test_execution_policies.h"
24 #include "type_algorithms.h"
26 template <class Iter>
27 struct Test {
28 template <class ExecutionPolicy>
29 void operator()(ExecutionPolicy&& policy) {
30 { // simple test
31 int a[10];
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
36 int a[10] {3};
37 std::generate(policy, Iter(std::begin(a)), Iter(std::begin(a)), []() { return 1; });
38 assert(a[0] == 3);
40 { // single-element range works
41 int a[] {3};
42 std::generate(policy, Iter(std::begin(a)), Iter(std::end(a)), []() { return 5; });
43 assert(a[0] == 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>{});
56 return 0;