copy.pass.cpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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<InputIterator InIter, OutputIterator<auto, InIter::reference> OutIter>
  10. // constexpr OutIter // constexpr after C++17
  11. // copy(InIter first, InIter last, OutIter result);
  12. #include <algorithm>
  13. #include <cassert>
  14. #include "test_macros.h"
  15. #include "test_iterators.h"
  16. // #if TEST_STD_VER > 17
  17. // TEST_CONSTEXPR bool test_constexpr() {
  18. // int ia[] = {1, 2, 3, 4, 5};
  19. // int ic[] = {6, 6, 6, 6, 6, 6, 6};
  20. //
  21. // auto p = std::copy(std::begin(ia), std::end(ia), std::begin(ic));
  22. // return std::equal(std::begin(ia), std::end(ia), std::begin(ic), p)
  23. // && std::all_of(p, std::end(ic), [](int a){return a == 6;})
  24. // ;
  25. // }
  26. // #endif
  27. template <class InIter, class OutIter>
  28. void
  29. test()
  30. {
  31. const unsigned N = 1000;
  32. int ia[N];
  33. for (unsigned i = 0; i < N; ++i)
  34. ia[i] = i;
  35. int ib[N] = {0};
  36. OutIter r = std::copy(InIter(ia), InIter(ia+N), OutIter(ib));
  37. assert(base(r) == ib+N);
  38. for (unsigned i = 0; i < N; ++i)
  39. assert(ia[i] == ib[i]);
  40. }
  41. int main(int, char**)
  42. {
  43. test<input_iterator<const int*>, output_iterator<int*> >();
  44. test<input_iterator<const int*>, input_iterator<int*> >();
  45. test<input_iterator<const int*>, forward_iterator<int*> >();
  46. test<input_iterator<const int*>, bidirectional_iterator<int*> >();
  47. test<input_iterator<const int*>, random_access_iterator<int*> >();
  48. test<input_iterator<const int*>, int*>();
  49. test<forward_iterator<const int*>, output_iterator<int*> >();
  50. test<forward_iterator<const int*>, input_iterator<int*> >();
  51. test<forward_iterator<const int*>, forward_iterator<int*> >();
  52. test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
  53. test<forward_iterator<const int*>, random_access_iterator<int*> >();
  54. test<forward_iterator<const int*>, int*>();
  55. test<bidirectional_iterator<const int*>, output_iterator<int*> >();
  56. test<bidirectional_iterator<const int*>, input_iterator<int*> >();
  57. test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
  58. test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
  59. test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
  60. test<bidirectional_iterator<const int*>, int*>();
  61. test<random_access_iterator<const int*>, output_iterator<int*> >();
  62. test<random_access_iterator<const int*>, input_iterator<int*> >();
  63. test<random_access_iterator<const int*>, forward_iterator<int*> >();
  64. test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
  65. test<random_access_iterator<const int*>, random_access_iterator<int*> >();
  66. test<random_access_iterator<const int*>, int*>();
  67. test<const int*, output_iterator<int*> >();
  68. test<const int*, input_iterator<int*> >();
  69. test<const int*, forward_iterator<int*> >();
  70. test<const int*, bidirectional_iterator<int*> >();
  71. test<const int*, random_access_iterator<int*> >();
  72. test<const int*, int*>();
  73. // #if TEST_STD_VER > 17
  74. // static_assert(test_constexpr());
  75. // #endif
  76. return 0;
  77. }