Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure |
| 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 | |
| 12 | // template<BidirectionalIterator Iter> |
| 13 | // requires HasSwap<Iter::reference, Iter::reference> |
| 14 | // void |
| 15 | // reverse(Iter first, Iter last); |
| 16 | |
| 17 | #include <algorithm> |
| 18 | #include <cassert> |
| 19 | |
| 20 | #include "../../iterators.h" |
| 21 | |
| 22 | template <class Iter> |
| 23 | void |
| 24 | test() |
| 25 | { |
| 26 | int ia[] = {0}; |
| 27 | const unsigned sa = sizeof(ia)/sizeof(ia[0]); |
| 28 | std::reverse(Iter(ia), Iter(ia)); |
| 29 | assert(ia[0] == 0); |
| 30 | std::reverse(Iter(ia), Iter(ia+sa)); |
| 31 | assert(ia[0] == 0); |
| 32 | |
| 33 | int ib[] = {0, 1}; |
| 34 | const unsigned sb = sizeof(ib)/sizeof(ib[0]); |
| 35 | std::reverse(Iter(ib), Iter(ib+sb)); |
| 36 | assert(ib[0] == 1); |
| 37 | assert(ib[1] == 0); |
| 38 | |
| 39 | int ic[] = {0, 1, 2}; |
| 40 | const unsigned sc = sizeof(ic)/sizeof(ic[0]); |
| 41 | std::reverse(Iter(ic), Iter(ic+sc)); |
| 42 | assert(ic[0] == 2); |
| 43 | assert(ic[1] == 1); |
| 44 | assert(ic[2] == 0); |
| 45 | |
| 46 | int id[] = {0, 1, 2, 3}; |
| 47 | const unsigned sd = sizeof(id)/sizeof(id[0]); |
| 48 | std::reverse(Iter(id), Iter(id+sd)); |
| 49 | assert(id[0] == 3); |
| 50 | assert(id[1] == 2); |
| 51 | assert(id[2] == 1); |
| 52 | assert(id[3] == 0); |
| 53 | } |
| 54 | |
| 55 | int main() |
| 56 | { |
| 57 | test<bidirectional_iterator<int*> >(); |
| 58 | test<random_access_iterator<int*> >(); |
| 59 | test<int*>(); |
| 60 | } |