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_n.pass.cpp
blob9506044acdbc0d7cf0ff3db02e26e2c44f5fa470
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 Size, class Generator>
14 // ForwardIterator generate_n(ExecutionPolicy&& exec,
15 // ForwardIterator first, Size n, Generator gen);
17 #include <algorithm>
18 #include <cassert>
19 #include <vector>
21 #include "test_iterators.h"
22 #include "test_execution_policies.h"
23 #include "type_algorithms.h"
25 template <class Iter>
26 struct Test {
27 template <class ExecutionPolicy>
28 void operator()(ExecutionPolicy&& policy) {
29 { // simple test
30 int a[10];
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
35 int a[10] {3};
36 std::generate_n(policy, Iter(std::begin(a)), 0, []() { return 1; });
37 assert(a[0] == 3);
39 { // single-element range works
40 int a[] {3};
41 std::generate_n(policy, Iter(std::begin(a)), std::size(a), []() { return 5; });
42 assert(a[0] == 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>{});
55 return 0;