1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // Older compilers don't support std::is_constant_evaluated
10 // UNSUPPORTED: clang-4, clang-5, clang-6, clang-7, clang-8
11 // UNSUPPORTED: apple-clang-9, apple-clang-10
15 // template<BidirectionalIterator InIter, BidirectionalIterator OutIter>
16 // requires OutputIterator<OutIter, RvalueOf<InIter::reference>::type>
18 // move_backward(InIter first, InIter last, OutIter result);
24 #include "test_macros.h"
25 #include "test_iterators.h"
27 template <class InIter
, class OutIter
>
28 TEST_CONSTEXPR_CXX17
bool
31 const unsigned N
= 1000;
33 for (unsigned i
= 0; i
< N
; ++i
)
37 OutIter r
= std::move_backward(InIter(ia
), InIter(ia
+N
), OutIter(ib
+N
));
38 assert(base(r
) == ib
);
39 for (unsigned i
= 0; i
< N
; ++i
)
40 assert(ia
[i
] == ib
[i
]);
45 #if TEST_STD_VER >= 11
46 template <class InIter
, class OutIter
>
50 const unsigned N
= 100;
51 std::unique_ptr
<int> ia
[N
];
52 for (unsigned i
= 0; i
< N
; ++i
)
53 ia
[i
].reset(new int(i
));
54 std::unique_ptr
<int> ib
[N
];
56 OutIter r
= std::move_backward(InIter(ia
), InIter(ia
+N
), OutIter(ib
+N
));
57 assert(base(r
) == ib
);
58 for (unsigned i
= 0; i
< N
; ++i
)
59 assert(*ib
[i
] == static_cast<int>(i
));
65 test
<bidirectional_iterator
<const int*>, bidirectional_iterator
<int*> >();
66 test
<bidirectional_iterator
<const int*>, random_access_iterator
<int*> >();
67 test
<bidirectional_iterator
<const int*>, int*>();
69 test
<random_access_iterator
<const int*>, bidirectional_iterator
<int*> >();
70 test
<random_access_iterator
<const int*>, random_access_iterator
<int*> >();
71 test
<random_access_iterator
<const int*>, int*>();
73 test
<const int*, bidirectional_iterator
<int*> >();
74 test
<const int*, random_access_iterator
<int*> >();
75 test
<const int*, int*>();
77 #if TEST_STD_VER >= 11
78 test1
<bidirectional_iterator
<std::unique_ptr
<int>*>, bidirectional_iterator
<std::unique_ptr
<int>*> >();
79 test1
<bidirectional_iterator
<std::unique_ptr
<int>*>, random_access_iterator
<std::unique_ptr
<int>*> >();
80 test1
<bidirectional_iterator
<std::unique_ptr
<int>*>, std::unique_ptr
<int>*>();
82 test1
<random_access_iterator
<std::unique_ptr
<int>*>, bidirectional_iterator
<std::unique_ptr
<int>*> >();
83 test1
<random_access_iterator
<std::unique_ptr
<int>*>, random_access_iterator
<std::unique_ptr
<int>*> >();
84 test1
<random_access_iterator
<std::unique_ptr
<int>*>, std::unique_ptr
<int>*>();
86 test1
<std::unique_ptr
<int>*, bidirectional_iterator
<std::unique_ptr
<int>*> >();
87 test1
<std::unique_ptr
<int>*, random_access_iterator
<std::unique_ptr
<int>*> >();
88 test1
<std::unique_ptr
<int>*, std::unique_ptr
<int>*>();
89 #endif // TEST_STD_VER >= 11
92 static_assert(test
<bidirectional_iterator
<const int*>, bidirectional_iterator
<int*> >());
93 static_assert(test
<bidirectional_iterator
<const int*>, random_access_iterator
<int*> >());
94 static_assert(test
<bidirectional_iterator
<const int*>, int*>());
96 static_assert(test
<random_access_iterator
<const int*>, bidirectional_iterator
<int*> >());
97 static_assert(test
<random_access_iterator
<const int*>, random_access_iterator
<int*> >());
98 static_assert(test
<random_access_iterator
<const int*>, int*>());
100 static_assert(test
<const int*, bidirectional_iterator
<int*> >());
101 static_assert(test
<const int*, random_access_iterator
<int*> >());
102 static_assert(test
<const int*, int*>());
103 #endif // TEST_STD_VER > 17