copy_backward.pass.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // <algorithm>
  9. // template<BidirectionalIterator InIter, BidirectionalIterator OutIter>
  10. // requires OutputIterator<OutIter, InIter::reference>
  11. // constexpr OutIter // constexpr after C++17
  12. // copy_backward(InIter first, InIter last, OutIter result);
  13. #include <algorithm>
  14. #include <cassert>
  15. #include "test_macros.h"
  16. #include "test_iterators.h"
  17. #include "user_defined_integral.h"
  18. // #if TEST_STD_VER > 17
  19. // TEST_CONSTEXPR bool test_constexpr() {
  20. // int ia[] = {1, 2, 3, 4, 5};
  21. // int ic[] = {6, 6, 6, 6, 6, 6, 6};
  22. //
  23. // size_t N = std::size(ia);
  24. // auto p = std::copy_backward(std::begin(ia), std::end(ia), std::begin(ic) + N);
  25. // return std::equal(std::begin(ic), p, std::begin(ia))
  26. // && std::all_of(p, std::end(ic), [](int a){return a == 6;})
  27. // ;
  28. // }
  29. // #endif
  30. template <class InIter, class OutIter>
  31. void
  32. test()
  33. {
  34. const unsigned N = 1000;
  35. int ia[N];
  36. for (unsigned i = 0; i < N; ++i)
  37. ia[i] = i;
  38. int ib[N] = {0};
  39. OutIter r = std::copy_backward(InIter(ia), InIter(ia+N), OutIter(ib+N));
  40. assert(base(r) == ib);
  41. for (unsigned i = 0; i < N; ++i)
  42. assert(ia[i] == ib[i]);
  43. }
  44. int main(int, char**)
  45. {
  46. test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
  47. test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
  48. test<bidirectional_iterator<const int*>, int*>();
  49. test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
  50. test<random_access_iterator<const int*>, random_access_iterator<int*> >();
  51. test<random_access_iterator<const int*>, int*>();
  52. test<const int*, bidirectional_iterator<int*> >();
  53. test<const int*, random_access_iterator<int*> >();
  54. test<const int*, int*>();
  55. // #if TEST_STD_VER > 17
  56. // static_assert(test_constexpr());
  57. // #endif
  58. return 0;
  59. }