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 //===----------------------------------------------------------------------===//
11 // template<InputIterator InIter, OutputIterator<auto, InIter::reference> OutIter>
12 // constexpr OutIter // constexpr after C++17
13 // copy(InIter first, InIter last, OutIter result);
18 #include "test_macros.h"
19 #include "test_iterators.h"
23 TEST_CONSTEXPR
PaddedBase(std::int16_t a
, std::int8_t b
) : a_(a
), b_(b
) {}
29 class Derived
: public PaddedBase
{
31 TEST_CONSTEXPR
Derived(std::int16_t a
, std::int8_t b
, std::int8_t c
) : PaddedBase(a
, b
), c_(c
) {}
36 template <class InIter
>
38 template <class OutIter
>
39 TEST_CONSTEXPR_CXX20
void operator()() {
40 const unsigned N
= 1000;
42 for (unsigned i
= 0; i
< N
; ++i
)
46 OutIter r
= std::copy(InIter(ia
), InIter(ia
+ N
), OutIter(ib
));
47 assert(base(r
) == ib
+ N
);
48 for (unsigned i
= 0; i
< N
; ++i
)
49 assert(ia
[i
] == ib
[i
]);
54 template <class InIter
>
55 TEST_CONSTEXPR_CXX20
void operator()() {
57 types::concatenate_t
<types::cpp17_input_iterator_list
<int*>, types::type_list
<cpp17_output_iterator
<int*> > >(),
62 TEST_CONSTEXPR_CXX20
bool test() {
63 types::for_each(types::cpp17_input_iterator_list
<int*>(), TestInIters());
65 { // Make sure that padding bits aren't copied
68 std::copy(static_cast<PaddedBase
*>(&src
), static_cast<PaddedBase
*>(&src
) + 1, static_cast<PaddedBase
*>(&dst
));
74 { // Make sure that overlapping ranges can be copied
75 int a
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
76 std::copy(a
+ 3, a
+ 10, a
);
77 int expected
[] = {4, 5, 6, 7, 8, 9, 10, 8, 9, 10};
78 assert(std::equal(a
, a
+ 10, expected
));
84 int main(int, char**) {
88 static_assert(test());