copy_backward.pass.cpp 1.5 KB

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