66 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410 11// UNSUPPORTED: libcpp-has-no-incomplete-pstl12 13// <algorithm>14 15// template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,16// class UnaryOperation>17// ForwardIterator218// transform(ExecutionPolicy&& exec,19// ForwardIterator1 first1, ForwardIterator1 last1,20// ForwardIterator2 result, UnaryOperation op);21 22#include <algorithm>23#include <cassert>24#include <vector>25 26#include "test_macros.h"27#include "test_execution_policies.h"28#include "test_iterators.h"29 30// We can't test the constraint on the execution policy, because that would conflict with the binary31// transform algorithm that doesn't take an execution policy, which is not constrained at all.32 33template <class Iter1, class Iter2>34struct Test {35 template <class Policy>36 void operator()(Policy&& policy) {37 // simple test38 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;42 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);52 }53 }54};55 56int 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 }});63 64 return 0;65}66