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_n(InIter first, InIter::difference_type n, OutIter result); 14 15 #include <algorithm> 16 #include <cassert> 17 18 #include "test_macros.h" 19 #include "test_iterators.h" 20 #include "user_defined_integral.h" 21 22 // #if TEST_STD_VER > 17 23 // TEST_CONSTEXPR bool test_constexpr() { 24 // int ia[] = {1, 2, 3, 4, 5}; 25 // int ic[] = {6, 6, 6, 6, 6, 6, 6}; 26 // 27 // auto p = std::copy_n(std::begin(ia), 4, std::begin(ic)); 28 // return std::equal(std::begin(ic), p, std::begin(ia)) 29 // && std::all_of(p, std::end(ic), [](int a){return a == 6;}) 30 // ; 31 // } 32 // #endif 33 34 typedef UserDefinedIntegral<unsigned> UDI; 35 36 template <class InIter, class OutIter> 37 void 38 test() 39 { 40 const unsigned N = 1000; 41 int ia[N]; 42 for (unsigned i = 0; i < N; ++i) 43 ia[i] = i; 44 int ib[N] = {0}; 45 46 OutIter r = std::copy_n(InIter(ia), UDI(N/2), OutIter(ib)); 47 assert(base(r) == ib+N/2); 48 for (unsigned i = 0; i < N/2; ++i) 49 assert(ia[i] == ib[i]); 50 } 51 52 int main(int, char**) 53 { 54 test<input_iterator<const int*>, output_iterator<int*> >(); 55 test<input_iterator<const int*>, input_iterator<int*> >(); 56 test<input_iterator<const int*>, forward_iterator<int*> >(); 57 test<input_iterator<const int*>, bidirectional_iterator<int*> >(); 58 test<input_iterator<const int*>, random_access_iterator<int*> >(); 59 test<input_iterator<const int*>, int*>(); 60 61 test<forward_iterator<const int*>, output_iterator<int*> >(); 62 test<forward_iterator<const int*>, input_iterator<int*> >(); 63 test<forward_iterator<const int*>, forward_iterator<int*> >(); 64 test<forward_iterator<const int*>, bidirectional_iterator<int*> >(); 65 test<forward_iterator<const int*>, random_access_iterator<int*> >(); 66 test<forward_iterator<const int*>, int*>(); 67 68 test<bidirectional_iterator<const int*>, output_iterator<int*> >(); 69 test<bidirectional_iterator<const int*>, input_iterator<int*> >(); 70 test<bidirectional_iterator<const int*>, forward_iterator<int*> >(); 71 test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >(); 72 test<bidirectional_iterator<const int*>, random_access_iterator<int*> >(); 73 test<bidirectional_iterator<const int*>, int*>(); 74 75 test<random_access_iterator<const int*>, output_iterator<int*> >(); 76 test<random_access_iterator<const int*>, input_iterator<int*> >(); 77 test<random_access_iterator<const int*>, forward_iterator<int*> >(); 78 test<random_access_iterator<const int*>, bidirectional_iterator<int*> >(); 79 test<random_access_iterator<const int*>, random_access_iterator<int*> >(); 80 test<random_access_iterator<const int*>, int*>(); 81 82 test<const int*, output_iterator<int*> >(); 83 test<const int*, input_iterator<int*> >(); 84 test<const int*, forward_iterator<int*> >(); 85 test<const int*, bidirectional_iterator<int*> >(); 86 test<const int*, random_access_iterator<int*> >(); 87 test<const int*, int*>(); 88 89 // #if TEST_STD_VER > 17 90 // static_assert(test_constexpr()); 91 // #endif 92 93 return 0; 94 } 95