• 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, BidirectionalIterator OutIter>
13 //   requires OutputIterator<OutIter, RvalueOf<InIter::reference>::type>
14 //   OutIter
15 //   move_backward(InIter first, InIter last, OutIter result);
16 
17 #include <algorithm>
18 #include <cassert>
19 #include <memory>
20 
21 #include "test_macros.h"
22 #include "test_iterators.h"
23 
24 template <class InIter, class OutIter>
25 void
test()26 test()
27 {
28     const unsigned N = 1000;
29     int ia[N];
30     for (unsigned i = 0; i < N; ++i)
31         ia[i] = i;
32     int ib[N] = {0};
33 
34     OutIter r = std::move_backward(InIter(ia), InIter(ia+N), OutIter(ib+N));
35     assert(base(r) == ib);
36     for (unsigned i = 0; i < N; ++i)
37         assert(ia[i] == ib[i]);
38 }
39 
40 #if TEST_STD_VER >= 11
41 template <class InIter, class OutIter>
42 void
test1()43 test1()
44 {
45     const unsigned N = 100;
46     std::unique_ptr<int> ia[N];
47     for (unsigned i = 0; i < N; ++i)
48         ia[i].reset(new int(i));
49     std::unique_ptr<int> ib[N];
50 
51     OutIter r = std::move_backward(InIter(ia), InIter(ia+N), OutIter(ib+N));
52     assert(base(r) == ib);
53     for (unsigned i = 0; i < N; ++i)
54         assert(*ib[i] == static_cast<int>(i));
55 }
56 #endif
57 
main()58 int main()
59 {
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*>, bidirectional_iterator<int*> >();
65     test<random_access_iterator<const int*>, random_access_iterator<int*> >();
66     test<random_access_iterator<const int*>, int*>();
67 
68     test<const int*, bidirectional_iterator<int*> >();
69     test<const int*, random_access_iterator<int*> >();
70     test<const int*, int*>();
71 
72 #if TEST_STD_VER >= 11
73     test1<bidirectional_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
74     test1<bidirectional_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
75     test1<bidirectional_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
76 
77     test1<random_access_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >();
78     test1<random_access_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >();
79     test1<random_access_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
80 
81     test1<std::unique_ptr<int>*, bidirectional_iterator<std::unique_ptr<int>*> >();
82     test1<std::unique_ptr<int>*, random_access_iterator<std::unique_ptr<int>*> >();
83     test1<std::unique_ptr<int>*, std::unique_ptr<int>*>();
84 #endif // TEST_STD_VER >= 11
85 }
86