• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, class T>
13 //   requires OutputIterator<OutIter, InIter::reference>
14 //         && OutputIterator<OutIter, const T&>
15 //         && HasEqualTo<InIter::value_type, T>
16 //   OutIter
17 //   replace_copy(InIter first, InIter last, OutIter result, const T& old_value,
18 //                                                           const T& new_value);
19 
20 #include <algorithm>
21 #include <cassert>
22 
23 #include "test_iterators.h"
24 
25 template <class InIter, class OutIter>
26 void
test()27 test()
28 {
29     int ia[] = {0, 1, 2, 3, 4};
30     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
31     int ib[sa] = {0};
32     OutIter r = std::replace_copy(InIter(ia), InIter(ia+sa), OutIter(ib), 2, 5);
33     assert(base(r) == ib + sa);
34     assert(ib[0] == 0);
35     assert(ib[1] == 1);
36     assert(ib[2] == 5);
37     assert(ib[3] == 3);
38     assert(ib[4] == 4);
39 }
40 
main()41 int main()
42 {
43     test<input_iterator<const int*>, output_iterator<int*> >();
44     test<input_iterator<const int*>, forward_iterator<int*> >();
45     test<input_iterator<const int*>, bidirectional_iterator<int*> >();
46     test<input_iterator<const int*>, random_access_iterator<int*> >();
47     test<input_iterator<const int*>, int*>();
48 
49     test<forward_iterator<const int*>, output_iterator<int*> >();
50     test<forward_iterator<const int*>, forward_iterator<int*> >();
51     test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
52     test<forward_iterator<const int*>, random_access_iterator<int*> >();
53     test<forward_iterator<const int*>, int*>();
54 
55     test<bidirectional_iterator<const int*>, output_iterator<int*> >();
56     test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
57     test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
58     test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
59     test<bidirectional_iterator<const int*>, int*>();
60 
61     test<random_access_iterator<const int*>, output_iterator<int*> >();
62     test<random_access_iterator<const int*>, forward_iterator<int*> >();
63     test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
64     test<random_access_iterator<const int*>, random_access_iterator<int*> >();
65     test<random_access_iterator<const int*>, int*>();
66 
67     test<const int*, output_iterator<int*> >();
68     test<const int*, forward_iterator<int*> >();
69     test<const int*, bidirectional_iterator<int*> >();
70     test<const int*, random_access_iterator<int*> >();
71     test<const int*, int*>();
72 }
73