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