• 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<BidirectionalIterator InIter, OutputIterator<auto, InIter::reference> OutIter>
13 //   OutIter
14 //   reverse_copy(InIter first, InIter last, OutIter result);
15 
16 #include <algorithm>
17 #include <cassert>
18 
19 #include "test_iterators.h"
20 
21 template <class InIter, class OutIter>
22 void
test()23 test()
24 {
25     const int ia[] = {0};
26     const unsigned sa = sizeof(ia)/sizeof(ia[0]);
27     int ja[sa] = {-1};
28     OutIter r = std::reverse_copy(InIter(ia), InIter(ia), OutIter(ja));
29     assert(base(r) == ja);
30     assert(ja[0] == -1);
31     r = std::reverse_copy(InIter(ia), InIter(ia+sa), OutIter(ja));
32     assert(ja[0] == 0);
33 
34     const int ib[] = {0, 1};
35     const unsigned sb = sizeof(ib)/sizeof(ib[0]);
36     int jb[sb] = {-1};
37     r = std::reverse_copy(InIter(ib), InIter(ib+sb), OutIter(jb));
38     assert(base(r) == jb+sb);
39     assert(jb[0] == 1);
40     assert(jb[1] == 0);
41 
42     const int ic[] = {0, 1, 2};
43     const unsigned sc = sizeof(ic)/sizeof(ic[0]);
44     int jc[sc] = {-1};
45     r = std::reverse_copy(InIter(ic), InIter(ic+sc), OutIter(jc));
46     assert(base(r) == jc+sc);
47     assert(jc[0] == 2);
48     assert(jc[1] == 1);
49     assert(jc[2] == 0);
50 
51     int id[] = {0, 1, 2, 3};
52     const unsigned sd = sizeof(id)/sizeof(id[0]);
53     int jd[sd] = {-1};
54     r = std::reverse_copy(InIter(id), InIter(id+sd), OutIter(jd));
55     assert(base(r) == jd+sd);
56     assert(jd[0] == 3);
57     assert(jd[1] == 2);
58     assert(jd[2] == 1);
59     assert(jd[3] == 0);
60 }
61 
main()62 int main()
63 {
64     test<bidirectional_iterator<const int*>, output_iterator<int*> >();
65     test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
66     test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
67     test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
68     test<bidirectional_iterator<const int*>, int*>();
69 
70     test<random_access_iterator<const int*>, output_iterator<int*> >();
71     test<random_access_iterator<const int*>, forward_iterator<int*> >();
72     test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
73     test<random_access_iterator<const int*>, random_access_iterator<int*> >();
74     test<random_access_iterator<const int*>, int*>();
75 
76     test<const int*, output_iterator<int*> >();
77     test<const int*, forward_iterator<int*> >();
78     test<const int*, bidirectional_iterator<int*> >();
79     test<const int*, random_access_iterator<int*> >();
80     test<const int*, int*>();
81 }
82