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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
10 // UNSUPPORTED: libcpp-has-no-incomplete-pstl
12 // template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
13 // class Predicate, class T>
15 // replace_copy_if(ExecutionPolicy&& exec,
16 // ForwardIterator1 first, ForwardIterator1 last,
17 // ForwardIterator2 result,
18 // Predicate pred, const T& new_value);
25 #include "type_algorithms.h"
26 #include "test_execution_policies.h"
27 #include "test_iterators.h"
31 template <class ExecutionPolicy
>
32 void operator()(ExecutionPolicy
&& policy
) {
34 std::array a
= {1, 2, 3, 4, 5, 6, 7, 8};
35 std::array
<int, a
.size()> out
;
37 policy
, Iter(std::begin(a
)), Iter(std::end(a
)), Iter(std::begin(out
)), [](int i
) { return i
== 3; }, 6);
38 assert((out
== std::array
{1, 2, 6, 4, 5, 6, 7, 8}));
41 { // empty range works
42 std::array
<int, 0> a
= {};
44 policy
, Iter(std::begin(a
)), Iter(std::end(a
)), Iter(std::begin(a
)), [](int i
) { return i
== 3; }, 6);
47 { // non-empty range without a match works
48 std::array a
= {1, 2};
49 std::array
<int, a
.size()> out
;
51 policy
, Iter(std::begin(a
)), Iter(std::end(a
)), Iter(out
.data()), [](int i
) { return i
== 3; }, 6);
52 assert((out
== std::array
{1, 2}));
55 { // single element range works
57 std::array
<int, a
.size()> out
;
59 policy
, Iter(std::begin(a
)), Iter(std::end(a
)), Iter(std::begin(out
)), [](int i
) { return i
== 3; }, 6);
60 assert((out
== std::array
{6}));
63 { // two element range works
64 std::array a
= {3, 4};
65 std::array
<int, a
.size()> out
;
67 policy
, Iter(std::begin(a
)), Iter(std::end(a
)), Iter(std::begin(out
)), [](int i
) { return i
== 3; }, 6);
68 assert((out
== std::array
{6, 4}));
71 { // multiple matching elements work
72 std::array a
= {1, 2, 3, 4, 3, 3, 5, 6, 3};
73 std::array
<int, a
.size()> out
;
75 policy
, Iter(std::begin(a
)), Iter(std::end(a
)), Iter(std::begin(out
)), [](int i
) { return i
== 3; }, 9);
76 assert((out
== std::array
{1, 2, 9, 4, 9, 9, 5, 6, 9}));
79 { // large range works
80 std::vector
<int> a(150, 3);
81 std::vector
<int> out(a
.size());
86 Iter(std::data(a
) + std::size(a
)),
88 [](int i
) { return i
== 3; },
91 std::vector
<int> comp(150, 6);
93 assert(std::equal(out
.begin(), out
.end(), comp
.begin()));
98 int main(int, char**) {
99 types::for_each(types::forward_iterator_list
<int*>{}, TestIteratorWithPolicies
<Test
>{});