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