Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <algorithm> |
| 11 | |
Howard Hinnant | eb564e7 | 2010-08-22 00:08:10 +0000 | [diff] [blame] | 12 | // template<BidirectionalIterator InIter, BidirectionalIterator OutIter> |
| 13 | // requires OutputIterator<OutIter, RvalueOf<InIter::reference>::type> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 14 | // OutIter |
| 15 | // move_backward(InIter first, InIter last, OutIter result); |
| 16 | |
| 17 | #include <algorithm> |
| 18 | #include <cassert> |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 19 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 20 | #include <memory> |
| 21 | #endif |
| 22 | |
| 23 | #include "../../iterators.h" |
| 24 | |
| 25 | template <class InIter, class OutIter> |
| 26 | void |
| 27 | test() |
| 28 | { |
| 29 | const unsigned N = 1000; |
| 30 | int ia[N]; |
| 31 | for (unsigned i = 0; i < N; ++i) |
| 32 | ia[i] = i; |
| 33 | int ib[N] = {0}; |
| 34 | |
| 35 | OutIter r = std::move_backward(InIter(ia), InIter(ia+N), OutIter(ib+N)); |
| 36 | assert(base(r) == ib); |
| 37 | for (unsigned i = 0; i < N; ++i) |
| 38 | assert(ia[i] == ib[i]); |
| 39 | } |
| 40 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 41 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 42 | |
| 43 | template <class InIter, class OutIter> |
| 44 | void |
| 45 | test1() |
| 46 | { |
| 47 | const unsigned N = 100; |
| 48 | std::unique_ptr<int> ia[N]; |
| 49 | for (unsigned i = 0; i < N; ++i) |
| 50 | ia[i].reset(new int(i)); |
| 51 | std::unique_ptr<int> ib[N]; |
| 52 | |
| 53 | OutIter r = std::move_backward(InIter(ia), InIter(ia+N), OutIter(ib+N)); |
| 54 | assert(base(r) == ib); |
| 55 | for (unsigned i = 0; i < N; ++i) |
| 56 | assert(*ib[i] == i); |
| 57 | } |
| 58 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 59 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 60 | |
| 61 | int main() |
| 62 | { |
| 63 | test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >(); |
| 64 | test<bidirectional_iterator<const int*>, random_access_iterator<int*> >(); |
| 65 | test<bidirectional_iterator<const int*>, int*>(); |
| 66 | |
| 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*, bidirectional_iterator<int*> >(); |
| 72 | test<const int*, random_access_iterator<int*> >(); |
| 73 | test<const int*, int*>(); |
| 74 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 75 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 76 | test1<bidirectional_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >(); |
| 77 | test1<bidirectional_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >(); |
| 78 | test1<bidirectional_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>(); |
| 79 | |
| 80 | test1<random_access_iterator<std::unique_ptr<int>*>, bidirectional_iterator<std::unique_ptr<int>*> >(); |
| 81 | test1<random_access_iterator<std::unique_ptr<int>*>, random_access_iterator<std::unique_ptr<int>*> >(); |
| 82 | test1<random_access_iterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>(); |
| 83 | |
| 84 | test1<std::unique_ptr<int>*, bidirectional_iterator<std::unique_ptr<int>*> >(); |
| 85 | test1<std::unique_ptr<int>*, random_access_iterator<std::unique_ptr<int>*> >(); |
| 86 | test1<std::unique_ptr<int>*, std::unique_ptr<int>*>(); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 87 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 88 | } |