[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / algorithms / alg.modifying.operations / alg.replace / replace_copy.pass.cpp
blobda3fabf406b16914dc3fad5833d44e5e382ba507
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, typename OutIter, class T>
12 // requires OutputIterator<OutIter, InIter::reference>
13 // && OutputIterator<OutIter, const T&>
14 // && HasEqualTo<InIter::value_type, T>
15 // constexpr OutIter // constexpr after C++17
16 // replace_copy(InIter first, InIter last, OutIter result, const T& old_value,
17 // const T& new_value);
19 #include <algorithm>
20 #include <cassert>
22 #include "test_macros.h"
23 #include "test_iterators.h"
26 #if TEST_STD_VER > 17
27 TEST_CONSTEXPR bool test_constexpr() {
28 int ia[] = {0, 1, 2, 3, 4};
29 int ib[] = {0, 0, 0, 0, 0, 0}; // one bigger
30 const int expected[] = {0, 1, 5, 3, 4};
32 auto it = std::replace_copy(std::begin(ia), std::end(ia), std::begin(ib), 2, 5);
34 return it == (std::begin(ib) + std::size(ia))
35 && *it == 0 // don't overwrite the last value in the output array
36 && std::equal(std::begin(ib), it, std::begin(expected), std::end(expected))
39 #endif
41 template <class InIter, class OutIter>
42 void
43 test()
45 int ia[] = {0, 1, 2, 3, 4};
46 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
47 int ib[sa] = {0};
48 OutIter r = std::replace_copy(InIter(ia), InIter(ia+sa), OutIter(ib), 2, 5);
49 assert(base(r) == ib + sa);
50 assert(ib[0] == 0);
51 assert(ib[1] == 1);
52 assert(ib[2] == 5);
53 assert(ib[3] == 3);
54 assert(ib[4] == 4);
57 int main(int, char**)
59 test<input_iterator<const int*>, output_iterator<int*> >();
60 test<input_iterator<const int*>, forward_iterator<int*> >();
61 test<input_iterator<const int*>, bidirectional_iterator<int*> >();
62 test<input_iterator<const int*>, random_access_iterator<int*> >();
63 test<input_iterator<const int*>, int*>();
65 test<forward_iterator<const int*>, output_iterator<int*> >();
66 test<forward_iterator<const int*>, forward_iterator<int*> >();
67 test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
68 test<forward_iterator<const int*>, random_access_iterator<int*> >();
69 test<forward_iterator<const int*>, int*>();
71 test<bidirectional_iterator<const int*>, output_iterator<int*> >();
72 test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
73 test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
74 test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
75 test<bidirectional_iterator<const int*>, int*>();
77 test<random_access_iterator<const int*>, output_iterator<int*> >();
78 test<random_access_iterator<const int*>, forward_iterator<int*> >();
79 test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
80 test<random_access_iterator<const int*>, random_access_iterator<int*> >();
81 test<random_access_iterator<const int*>, int*>();
83 test<const int*, output_iterator<int*> >();
84 test<const int*, forward_iterator<int*> >();
85 test<const int*, bidirectional_iterator<int*> >();
86 test<const int*, random_access_iterator<int*> >();
87 test<const int*, int*>();
89 #if TEST_STD_VER > 17
90 static_assert(test_constexpr());
91 #endif
93 return 0;