[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / algorithms / alg.modifying.operations / alg.replace / replace_if.pass.cpp
blob4f32b6e94a4132598a8804cfd4d638ad77a5405b
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<ForwardIterator Iter, Predicate<auto, Iter::value_type> Pred, class T>
12 // requires OutputIterator<Iter, Iter::reference>
13 // && OutputIterator<Iter, const T&>
14 // && CopyConstructible<Pred>
15 // constexpr void // constexpr after C++17
16 // replace_if(Iter first, Iter last, Pred pred, const T& new_value);
18 #include <algorithm>
19 #include <functional>
20 #include <cassert>
22 #include "test_macros.h"
23 #include "test_iterators.h"
25 TEST_CONSTEXPR bool equalToTwo(int v) { return v == 2; }
27 #if TEST_STD_VER > 17
28 TEST_CONSTEXPR bool test_constexpr() {
29 int ia[] = {0, 1, 2, 3, 4};
30 const int expected[] = {0, 1, 5, 3, 4};
32 std::replace_if(std::begin(ia), std::end(ia), equalToTwo, 5);
33 return std::equal(std::begin(ia), std::end(ia), std::begin(expected), std::end(expected))
36 #endif
39 template <class Iter>
40 void
41 test()
43 int ia[] = {0, 1, 2, 3, 4};
44 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
45 std::replace_if(Iter(ia), Iter(ia+sa), equalToTwo, 5);
46 assert(ia[0] == 0);
47 assert(ia[1] == 1);
48 assert(ia[2] == 5);
49 assert(ia[3] == 3);
50 assert(ia[4] == 4);
53 int main(int, char**)
55 test<forward_iterator<int*> >();
56 test<bidirectional_iterator<int*> >();
57 test<random_access_iterator<int*> >();
58 test<int*>();
60 #if TEST_STD_VER > 17
61 static_assert(test_constexpr());
62 #endif
64 return 0;