Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / algorithms / alg.modifying.operations / alg.transform / pstl.transform.unary.pass.cpp
blob03985c7d3673be189c66c526c69c459f8545b967
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 // <algorithm>
15 // template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
16 // class UnaryOperation>
17 // ForwardIterator2
18 // transform(ExecutionPolicy&& exec,
19 // ForwardIterator1 first1, ForwardIterator1 last1,
20 // ForwardIterator2 result, UnaryOperation op);
22 #include <algorithm>
23 #include <cassert>
24 #include <vector>
26 #include "test_macros.h"
27 #include "test_execution_policies.h"
28 #include "test_iterators.h"
30 // We can't test the constraint on the execution policy, because that would conflict with the binary
31 // transform algorithm that doesn't take an execution policy, which is not constrained at all.
33 template <class Iter1, class Iter2>
34 struct Test {
35 template <class Policy>
36 void operator()(Policy&& policy) {
37 // simple test
38 for (const int size : {0, 1, 2, 100, 350}) {
39 std::vector<int> a(size);
40 for (int i = 0; i != size; ++i)
41 a[i] = i + 1;
43 std::vector<int> out(std::size(a));
44 decltype(auto) ret = std::transform(
45 policy, Iter1(std::data(a)), Iter1(std::data(a) + std::size(a)), Iter2(std::data(out)), [](int i) {
46 return i + 3;
47 });
48 static_assert(std::is_same_v<decltype(ret), Iter2>);
49 assert(base(ret) == std::data(out) + std::size(out));
50 for (int i = 0; i != size; ++i)
51 assert(out[i] == i + 4);
56 int main(int, char**) {
57 types::for_each(types::forward_iterator_list<int*>{}, types::apply_type_identity{[](auto v) {
58 using Iter = typename decltype(v)::type;
59 types::for_each(
60 types::forward_iterator_list<int*>{},
61 TestIteratorWithPolicies<types::partial_instantiation<Test, Iter>::template apply>{});
62 }});
64 return 0;