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