reverse.pass.cpp 1.5 KB

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