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, typename OutIter>
12 // requires OutputIterator<OutIter, RvalueOf<InIter::reference>::type>
14 // move(InIter first, InIter last, OutIter result);
16 // Older compilers don't support std::is_constant_evaluated
17 // UNSUPPORTED: clang-4, clang-5, clang-6, clang-7, clang-8
18 // UNSUPPORTED: apple-clang-9, apple-clang-10, apple-clang-11
19 // UNSUPPORTED: gcc-5, gcc-6, gcc-7, gcc-8
25 #include "test_macros.h"
26 #include "test_iterators.h"
28 template <class InIter
, class OutIter
>
29 TEST_CONSTEXPR_CXX17
bool
32 const unsigned N
= 1000;
34 for (unsigned i
= 0; i
< N
; ++i
)
38 OutIter r
= std::move(InIter(ia
), InIter(ia
+N
), OutIter(ib
));
39 assert(base(r
) == ib
+N
);
40 for (unsigned i
= 0; i
< N
; ++i
)
41 assert(ia
[i
] == ib
[i
]);
46 #if TEST_STD_VER >= 11
47 template <class InIter
, class OutIter
>
51 const unsigned N
= 100;
52 std::unique_ptr
<int> ia
[N
];
53 for (unsigned i
= 0; i
< N
; ++i
)
54 ia
[i
].reset(new int(i
));
55 std::unique_ptr
<int> ib
[N
];
57 OutIter r
= std::move(InIter(ia
), InIter(ia
+N
), OutIter(ib
));
58 assert(base(r
) == ib
+N
);
59 for (unsigned i
= 0; i
< N
; ++i
)
60 assert(*ib
[i
] == static_cast<int>(i
));
66 test
<input_iterator
<const int*>, output_iterator
<int*> >();
67 test
<input_iterator
<const int*>, input_iterator
<int*> >();
68 test
<input_iterator
<const int*>, forward_iterator
<int*> >();
69 test
<input_iterator
<const int*>, bidirectional_iterator
<int*> >();
70 test
<input_iterator
<const int*>, random_access_iterator
<int*> >();
71 test
<input_iterator
<const int*>, int*>();
73 test
<forward_iterator
<const int*>, output_iterator
<int*> >();
74 test
<forward_iterator
<const int*>, input_iterator
<int*> >();
75 test
<forward_iterator
<const int*>, forward_iterator
<int*> >();
76 test
<forward_iterator
<const int*>, bidirectional_iterator
<int*> >();
77 test
<forward_iterator
<const int*>, random_access_iterator
<int*> >();
78 test
<forward_iterator
<const int*>, int*>();
80 test
<bidirectional_iterator
<const int*>, output_iterator
<int*> >();
81 test
<bidirectional_iterator
<const int*>, input_iterator
<int*> >();
82 test
<bidirectional_iterator
<const int*>, forward_iterator
<int*> >();
83 test
<bidirectional_iterator
<const int*>, bidirectional_iterator
<int*> >();
84 test
<bidirectional_iterator
<const int*>, random_access_iterator
<int*> >();
85 test
<bidirectional_iterator
<const int*>, int*>();
87 test
<random_access_iterator
<const int*>, output_iterator
<int*> >();
88 test
<random_access_iterator
<const int*>, input_iterator
<int*> >();
89 test
<random_access_iterator
<const int*>, forward_iterator
<int*> >();
90 test
<random_access_iterator
<const int*>, bidirectional_iterator
<int*> >();
91 test
<random_access_iterator
<const int*>, random_access_iterator
<int*> >();
92 test
<random_access_iterator
<const int*>, int*>();
94 test
<const int*, output_iterator
<int*> >();
95 test
<const int*, input_iterator
<int*> >();
96 test
<const int*, forward_iterator
<int*> >();
97 test
<const int*, bidirectional_iterator
<int*> >();
98 test
<const int*, random_access_iterator
<int*> >();
99 test
<const int*, int*>();
101 #if TEST_STD_VER >= 11
102 test1
<input_iterator
<std::unique_ptr
<int>*>, output_iterator
<std::unique_ptr
<int>*> >();
103 test1
<input_iterator
<std::unique_ptr
<int>*>, input_iterator
<std::unique_ptr
<int>*> >();
104 test1
<input_iterator
<std::unique_ptr
<int>*>, forward_iterator
<std::unique_ptr
<int>*> >();
105 test1
<input_iterator
<std::unique_ptr
<int>*>, bidirectional_iterator
<std::unique_ptr
<int>*> >();
106 test1
<input_iterator
<std::unique_ptr
<int>*>, random_access_iterator
<std::unique_ptr
<int>*> >();
107 test1
<input_iterator
<std::unique_ptr
<int>*>, std::unique_ptr
<int>*>();
109 test1
<forward_iterator
<std::unique_ptr
<int>*>, output_iterator
<std::unique_ptr
<int>*> >();
110 test1
<forward_iterator
<std::unique_ptr
<int>*>, input_iterator
<std::unique_ptr
<int>*> >();
111 test1
<forward_iterator
<std::unique_ptr
<int>*>, forward_iterator
<std::unique_ptr
<int>*> >();
112 test1
<forward_iterator
<std::unique_ptr
<int>*>, bidirectional_iterator
<std::unique_ptr
<int>*> >();
113 test1
<forward_iterator
<std::unique_ptr
<int>*>, random_access_iterator
<std::unique_ptr
<int>*> >();
114 test1
<forward_iterator
<std::unique_ptr
<int>*>, std::unique_ptr
<int>*>();
116 test1
<bidirectional_iterator
<std::unique_ptr
<int>*>, output_iterator
<std::unique_ptr
<int>*> >();
117 test1
<bidirectional_iterator
<std::unique_ptr
<int>*>, input_iterator
<std::unique_ptr
<int>*> >();
118 test1
<bidirectional_iterator
<std::unique_ptr
<int>*>, forward_iterator
<std::unique_ptr
<int>*> >();
119 test1
<bidirectional_iterator
<std::unique_ptr
<int>*>, bidirectional_iterator
<std::unique_ptr
<int>*> >();
120 test1
<bidirectional_iterator
<std::unique_ptr
<int>*>, random_access_iterator
<std::unique_ptr
<int>*> >();
121 test1
<bidirectional_iterator
<std::unique_ptr
<int>*>, std::unique_ptr
<int>*>();
123 test1
<random_access_iterator
<std::unique_ptr
<int>*>, output_iterator
<std::unique_ptr
<int>*> >();
124 test1
<random_access_iterator
<std::unique_ptr
<int>*>, input_iterator
<std::unique_ptr
<int>*> >();
125 test1
<random_access_iterator
<std::unique_ptr
<int>*>, forward_iterator
<std::unique_ptr
<int>*> >();
126 test1
<random_access_iterator
<std::unique_ptr
<int>*>, bidirectional_iterator
<std::unique_ptr
<int>*> >();
127 test1
<random_access_iterator
<std::unique_ptr
<int>*>, random_access_iterator
<std::unique_ptr
<int>*> >();
128 test1
<random_access_iterator
<std::unique_ptr
<int>*>, std::unique_ptr
<int>*>();
130 test1
<std::unique_ptr
<int>*, output_iterator
<std::unique_ptr
<int>*> >();
131 test1
<std::unique_ptr
<int>*, input_iterator
<std::unique_ptr
<int>*> >();
132 test1
<std::unique_ptr
<int>*, forward_iterator
<std::unique_ptr
<int>*> >();
133 test1
<std::unique_ptr
<int>*, bidirectional_iterator
<std::unique_ptr
<int>*> >();
134 test1
<std::unique_ptr
<int>*, random_access_iterator
<std::unique_ptr
<int>*> >();
135 test1
<std::unique_ptr
<int>*, std::unique_ptr
<int>*>();
136 #endif // TEST_STD_VER >= 11
138 #if TEST_STD_VER > 17
139 static_assert(test
<input_iterator
<const int*>, input_iterator
<int*> >());
140 static_assert(test
<input_iterator
<const int*>, forward_iterator
<int*> >());
141 static_assert(test
<input_iterator
<const int*>, bidirectional_iterator
<int*> >());
142 static_assert(test
<input_iterator
<const int*>, random_access_iterator
<int*> >());
143 static_assert(test
<input_iterator
<const int*>, int*>());
145 static_assert(test
<forward_iterator
<const int*>, input_iterator
<int*> >());
146 static_assert(test
<forward_iterator
<const int*>, forward_iterator
<int*> >());
147 static_assert(test
<forward_iterator
<const int*>, bidirectional_iterator
<int*> >());
148 static_assert(test
<forward_iterator
<const int*>, random_access_iterator
<int*> >());
149 static_assert(test
<forward_iterator
<const int*>, int*>());
151 static_assert(test
<bidirectional_iterator
<const int*>, input_iterator
<int*> >());
152 static_assert(test
<bidirectional_iterator
<const int*>, forward_iterator
<int*> >());
153 static_assert(test
<bidirectional_iterator
<const int*>, bidirectional_iterator
<int*> >());
154 static_assert(test
<bidirectional_iterator
<const int*>, random_access_iterator
<int*> >());
155 static_assert(test
<bidirectional_iterator
<const int*>, int*>());
157 static_assert(test
<random_access_iterator
<const int*>, input_iterator
<int*> >());
158 static_assert(test
<random_access_iterator
<const int*>, forward_iterator
<int*> >());
159 static_assert(test
<random_access_iterator
<const int*>, bidirectional_iterator
<int*> >());
160 static_assert(test
<random_access_iterator
<const int*>, random_access_iterator
<int*> >());
161 static_assert(test
<random_access_iterator
<const int*>, int*>());
163 static_assert(test
<const int*, input_iterator
<int*> >());
164 static_assert(test
<const int*, forward_iterator
<int*> >());
165 static_assert(test
<const int*, bidirectional_iterator
<int*> >());
166 static_assert(test
<const int*, random_access_iterator
<int*> >());
167 static_assert(test
<const int*, int*>());
168 #endif // TEST_STD_VER > 17