1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <algorithm>
11
12 // template<BidirectionalIterator InIter, BidirectionalIterator OutIter>
13 // requires OutputIterator<OutIter, InIter::reference>
14 // constexpr OutIter // constexpr after C++17
15 // copy_backward(InIter first, InIter last, OutIter result);
16
17 #include <algorithm>
18 #include <cassert>
19
20 #include "test_macros.h"
21 #include "test_iterators.h"
22 #include "user_defined_integral.hpp"
23
24 // #if TEST_STD_VER > 17
25 // TEST_CONSTEXPR bool test_constexpr() {
26 // int ia[] = {1, 2, 3, 4, 5};
27 // int ic[] = {6, 6, 6, 6, 6, 6, 6};
28 //
29 // size_t N = std::size(ia);
30 // auto p = std::copy_backward(std::begin(ia), std::end(ia), std::begin(ic) + N);
31 // return std::equal(std::begin(ic), p, std::begin(ia))
32 // && std::all_of(p, std::end(ic), [](int a){return a == 6;})
33 // ;
34 // }
35 // #endif
36
37 template <class InIter, class OutIter>
38 void
test()39 test()
40 {
41 const unsigned N = 1000;
42 int ia[N];
43 for (unsigned i = 0; i < N; ++i)
44 ia[i] = i;
45 int ib[N] = {0};
46
47 OutIter r = std::copy_backward(InIter(ia), InIter(ia+N), OutIter(ib+N));
48 assert(base(r) == ib);
49 for (unsigned i = 0; i < N; ++i)
50 assert(ia[i] == ib[i]);
51 }
52
main()53 int main()
54 {
55 test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
56 test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
57 test<bidirectional_iterator<const int*>, int*>();
58
59 test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
60 test<random_access_iterator<const int*>, random_access_iterator<int*> >();
61 test<random_access_iterator<const int*>, int*>();
62
63 test<const int*, bidirectional_iterator<int*> >();
64 test<const int*, random_access_iterator<int*> >();
65 test<const int*, int*>();
66
67 // #if TEST_STD_VER > 17
68 // static_assert(test_constexpr());
69 // #endif
70 }
71