[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / algorithms / alg.modifying.operations / alg.transform / unary_transform.pass.cpp
blob85c3868207bcf6ade64089746d217d429c63e35b
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 // <algorithm>
11 // template<InputIterator InIter, class OutIter,
12 // Callable<auto, const InIter::value_type&> Op>
13 // requires OutputIterator<OutIter, Op::result_type> && CopyConstructible<Op>
14 // constexpr OutIter // constexpr after C++17
15 // transform(InIter first, InIter last, OutIter result, Op op);
17 #include <algorithm>
18 #include <functional>
19 #include <cassert>
21 #include "test_macros.h"
22 #include "test_iterators.h"
24 TEST_CONSTEXPR int plusOne(int v) { return v + 1; }
27 #if TEST_STD_VER > 17
28 TEST_CONSTEXPR bool test_constexpr() {
29 int ia[] = {1, 3, 6, 7};
30 int ib[] = {0, 0, 0, 0, 0}; // one bigger
31 const int expected[] = {2, 4, 7, 8};
33 auto it = std::transform(std::begin(ia), std::end(ia), std::begin(ib), plusOne);
35 return it == (std::begin(ib) + std::size(ia))
36 && *it == 0 // don't overwrite the last value in the output array
37 && std::equal(std::begin(ib), it, std::begin(expected), std::end(expected))
40 #endif
43 template <class InIter, class OutIter>
44 void
45 test()
47 int ia[] = {0, 1, 2, 3, 4};
48 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
49 int ib[sa] = {0};
50 OutIter r = std::transform(InIter(ia), InIter(ia+sa),
51 OutIter(ib), plusOne);
52 assert(base(r) == ib + sa);
53 assert(ib[0] == 1);
54 assert(ib[1] == 2);
55 assert(ib[2] == 3);
56 assert(ib[3] == 4);
57 assert(ib[4] == 5);
60 int main(int, char**)
62 test<input_iterator<const int*>, output_iterator<int*> >();
63 test<input_iterator<const int*>, input_iterator<int*> >();
64 test<input_iterator<const int*>, forward_iterator<int*> >();
65 test<input_iterator<const int*>, bidirectional_iterator<int*> >();
66 test<input_iterator<const int*>, random_access_iterator<int*> >();
67 test<input_iterator<const int*>, int*>();
69 test<forward_iterator<const int*>, output_iterator<int*> >();
70 test<forward_iterator<const int*>, input_iterator<int*> >();
71 test<forward_iterator<const int*>, forward_iterator<int*> >();
72 test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
73 test<forward_iterator<const int*>, random_access_iterator<int*> >();
74 test<forward_iterator<const int*>, int*>();
76 test<bidirectional_iterator<const int*>, output_iterator<int*> >();
77 test<bidirectional_iterator<const int*>, input_iterator<int*> >();
78 test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
79 test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
80 test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
81 test<bidirectional_iterator<const int*>, int*>();
83 test<random_access_iterator<const int*>, output_iterator<int*> >();
84 test<random_access_iterator<const int*>, input_iterator<int*> >();
85 test<random_access_iterator<const int*>, forward_iterator<int*> >();
86 test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
87 test<random_access_iterator<const int*>, random_access_iterator<int*> >();
88 test<random_access_iterator<const int*>, int*>();
90 test<const int*, output_iterator<int*> >();
91 test<const int*, input_iterator<int*> >();
92 test<const int*, forward_iterator<int*> >();
93 test<const int*, bidirectional_iterator<int*> >();
94 test<const int*, random_access_iterator<int*> >();
95 test<const int*, int*>();
97 #if TEST_STD_VER > 17
98 static_assert(test_constexpr());
99 #endif
101 return 0;