1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <algorithm>
11
12 // template<InputIterator InIter, typename OutIter,
13 // Predicate<auto, InIter::value_type> Pred, class T>
14 // requires OutputIterator<OutIter, InIter::reference>
15 // && OutputIterator<OutIter, const T&>
16 // && CopyConstructible<Pred>
17 // OutIter
18 // replace_copy_if(InIter first, InIter last, OutIter result, Pred pred, const T& new_value);
19
20 #include <algorithm>
21 #include <functional>
22 #include <cassert>
23
24 #include "test_iterators.h"
25
26 template <class InIter, class OutIter>
27 void
test()28 test()
29 {
30 int ia[] = {0, 1, 2, 3, 4};
31 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
32 int ib[sa] = {0};
33 OutIter r = std::replace_copy_if(InIter(ia), InIter(ia+sa), OutIter(ib),
34 std::bind2nd(std::equal_to<int>(), 2), 5);
35 assert(base(r) == ib + sa);
36 assert(ib[0] == 0);
37 assert(ib[1] == 1);
38 assert(ib[2] == 5);
39 assert(ib[3] == 3);
40 assert(ib[4] == 4);
41 }
42
main()43 int main()
44 {
45 test<input_iterator<const int*>, output_iterator<int*> >();
46 test<input_iterator<const int*>, forward_iterator<int*> >();
47 test<input_iterator<const int*>, bidirectional_iterator<int*> >();
48 test<input_iterator<const int*>, random_access_iterator<int*> >();
49 test<input_iterator<const int*>, int*>();
50
51 test<forward_iterator<const int*>, output_iterator<int*> >();
52 test<forward_iterator<const int*>, forward_iterator<int*> >();
53 test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
54 test<forward_iterator<const int*>, random_access_iterator<int*> >();
55 test<forward_iterator<const int*>, int*>();
56
57 test<bidirectional_iterator<const int*>, output_iterator<int*> >();
58 test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
59 test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
60 test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
61 test<bidirectional_iterator<const int*>, int*>();
62
63 test<random_access_iterator<const int*>, output_iterator<int*> >();
64 test<random_access_iterator<const int*>, forward_iterator<int*> >();
65 test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
66 test<random_access_iterator<const int*>, random_access_iterator<int*> >();
67 test<random_access_iterator<const int*>, int*>();
68
69 test<const int*, output_iterator<int*> >();
70 test<const int*, forward_iterator<int*> >();
71 test<const int*, bidirectional_iterator<int*> >();
72 test<const int*, random_access_iterator<int*> >();
73 test<const int*, int*>();
74 }
75