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, class OutIter,
13 // Callable<auto, const InIter::value_type&> Op>
14 // requires OutputIterator<OutIter, Op::result_type> && CopyConstructible<Op>
15 // OutIter
16 // transform(InIter first, InIter last, OutIter result, Op op);
17
18 #include <algorithm>
19 #include <functional>
20 #include <cassert>
21
22 #include "test_iterators.h"
23
24 template <class InIter, class OutIter>
25 void
test()26 test()
27 {
28 int ia[] = {0, 1, 2, 3, 4};
29 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
30 int ib[sa] = {0};
31 OutIter r = std::transform(InIter(ia), InIter(ia+sa), OutIter(ib),
32 std::bind2nd(std::plus<int>(), 1));
33 assert(base(r) == ib + sa);
34 assert(ib[0] == 1);
35 assert(ib[1] == 2);
36 assert(ib[2] == 3);
37 assert(ib[3] == 4);
38 assert(ib[4] == 5);
39 }
40
main()41 int main()
42 {
43 test<input_iterator<const int*>, output_iterator<int*> >();
44 test<input_iterator<const int*>, input_iterator<int*> >();
45 test<input_iterator<const int*>, forward_iterator<int*> >();
46 test<input_iterator<const int*>, bidirectional_iterator<int*> >();
47 test<input_iterator<const int*>, random_access_iterator<int*> >();
48 test<input_iterator<const int*>, int*>();
49
50 test<forward_iterator<const int*>, output_iterator<int*> >();
51 test<forward_iterator<const int*>, input_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*>, input_iterator<int*> >();
59 test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
60 test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
61 test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
62 test<bidirectional_iterator<const int*>, int*>();
63
64 test<random_access_iterator<const int*>, output_iterator<int*> >();
65 test<random_access_iterator<const int*>, input_iterator<int*> >();
66 test<random_access_iterator<const int*>, forward_iterator<int*> >();
67 test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
68 test<random_access_iterator<const int*>, random_access_iterator<int*> >();
69 test<random_access_iterator<const int*>, int*>();
70
71 test<const int*, output_iterator<int*> >();
72 test<const int*, input_iterator<int*> >();
73 test<const int*, forward_iterator<int*> >();
74 test<const int*, bidirectional_iterator<int*> >();
75 test<const int*, random_access_iterator<int*> >();
76 test<const int*, int*>();
77 }
78