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