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, OutputIterator<auto, InIter::reference> OutIter,
13eb564e76cc3904d811c981a50ecce0659f444cc9Howard Hinnant//          Predicate<auto, InIter::value_type> Pred>
14eb564e76cc3904d811c981a50ecce0659f444cc9Howard Hinnant//   requires CopyConstructible<Pred>
15bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//   OutIter
16bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//   copy_if(InIter first, InIter last, OutIter result, Pred pred);
17bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
18bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include <algorithm>
19bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include <cassert>
20bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
2183e2c4d877fe2d7793868b1c6a5d9525a7c4d431Marshall Clow#include "test_iterators.h"
22bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
23bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantstruct Pred
24bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{
25bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    bool operator()(int i) {return i % 3 == 0;}
26bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant};
27bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
28bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnanttemplate <class InIter, class OutIter>
29bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantvoid
30bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnanttest()
31bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{
32bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    const unsigned N = 1000;
33bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    int ia[N];
34bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    for (unsigned i = 0; i < N; ++i)
35bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        ia[i] = i;
36bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    int ib[N] = {0};
37bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
38bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    OutIter r = std::copy_if(InIter(ia), InIter(ia+N), OutIter(ib), Pred());
39bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    assert(base(r) == ib+N/3+1);
40bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    for (unsigned i = 0; i < N/3+1; ++i)
41bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(ib[i] % 3 == 0);
42bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant}
43bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
44bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantint main()
45bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{
46bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<input_iterator<const int*>, output_iterator<int*> >();
47bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<input_iterator<const int*>, input_iterator<int*> >();
48bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<input_iterator<const int*>, forward_iterator<int*> >();
49bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<input_iterator<const int*>, bidirectional_iterator<int*> >();
50bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<input_iterator<const int*>, random_access_iterator<int*> >();
51bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<input_iterator<const int*>, int*>();
52bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
53bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<forward_iterator<const int*>, output_iterator<int*> >();
54bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<forward_iterator<const int*>, input_iterator<int*> >();
55bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<forward_iterator<const int*>, forward_iterator<int*> >();
56bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
57bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<forward_iterator<const int*>, random_access_iterator<int*> >();
58bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<forward_iterator<const int*>, int*>();
59bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
60bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<bidirectional_iterator<const int*>, output_iterator<int*> >();
61bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<bidirectional_iterator<const int*>, input_iterator<int*> >();
62bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
63bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
64bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
65bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<bidirectional_iterator<const int*>, int*>();
66bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
67bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<random_access_iterator<const int*>, output_iterator<int*> >();
68bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<random_access_iterator<const int*>, input_iterator<int*> >();
69bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<random_access_iterator<const int*>, forward_iterator<int*> >();
70bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
71bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<random_access_iterator<const int*>, random_access_iterator<int*> >();
72bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<random_access_iterator<const int*>, int*>();
73bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
74bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<const int*, output_iterator<int*> >();
75bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<const int*, input_iterator<int*> >();
76bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<const int*, forward_iterator<int*> >();
77bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<const int*, bidirectional_iterator<int*> >();
78bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<const int*, random_access_iterator<int*> >();
79bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<const int*, int*>();
80bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant}
81