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<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);
22 #include "test_macros.h"
23 #include "test_iterators.h"
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
))
41 template <class InIter
, class OutIter
>
45 int ia
[] = {0, 1, 2, 3, 4};
46 const unsigned sa
= sizeof(ia
)/sizeof(ia
[0]);
48 OutIter r
= std::replace_copy(InIter(ia
), InIter(ia
+sa
), OutIter(ib
), 2, 5);
49 assert(base(r
) == ib
+ sa
);
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*>();
90 static_assert(test_constexpr());