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, BidirectionalIterator OutIter>
13 //   requires OutputIterator<OutIter, InIter::reference>
14 //   OutIter
15 //   copy_backward(InIter first, InIter last, OutIter result);
16 
17 #include <algorithm>
18 #include <cassert>
19 
20 #include "test_iterators.h"
21 
22 template <class InIter, class OutIter>
23 void
24 test()
25 {
26     const unsigned N = 1000;
27     int ia[N];
28     for (unsigned i = 0; i < N; ++i)
29         ia[i] = i;
30     int ib[N] = {0};
31 
32     OutIter r = std::copy_backward(InIter(ia), InIter(ia+N), OutIter(ib+N));
33     assert(base(r) == ib);
34     for (unsigned i = 0; i < N; ++i)
35         assert(ia[i] == ib[i]);
36 }
37 
38 int main()
39 {
40     test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
41     test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
42     test<bidirectional_iterator<const int*>, int*>();
43 
44     test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
45     test<random_access_iterator<const int*>, random_access_iterator<int*> >();
46     test<random_access_iterator<const int*>, int*>();
47 
48     test<const int*, bidirectional_iterator<int*> >();
49     test<const int*, random_access_iterator<int*> >();
50     test<const int*, int*>();
51 }
52