1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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);
22 #include "test_macros.h"
23 #include "test_iterators.h"
25 TEST_CONSTEXPR
bool equalToTwo(int v
) { return v
== 2; }
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
))
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);
55 test
<forward_iterator
<int*> >();
56 test
<bidirectional_iterator
<int*> >();
57 test
<random_access_iterator
<int*> >();
61 static_assert(test_constexpr());