9 #ifndef LLVM_ADT_TINYPTRVECTOR_H
10 #define LLVM_ADT_TINYPTRVECTOR_H
19 #include <type_traits>
29 template <
typename EltTy>
47 if (
VecTy *V = Val.template dyn_cast<VecTy*>())
52 if (
VecTy *V = Val.template dyn_cast<VecTy*>())
66 if (Val.template is<EltTy>()) {
70 Val =
new VecTy(*
RHS.Val.template get<VecTy*>());
75 if (
RHS.Val.template is<EltTy>()) {
76 Val.template get<VecTy*>()->clear();
77 Val.template get<VecTy*>()->push_back(
RHS.front());
79 *Val.template get<VecTy*>() = *
RHS.Val.template get<VecTy*>();
85 RHS.Val = (EltTy)
nullptr;
99 if (
VecTy *V = Val.template dyn_cast<VecTy*>()) {
100 if (
RHS.Val.template is<EltTy>()) {
102 V->push_back(
RHS.front());
140 if (Val.template is<EltTy>())
142 return *Val.template get<VecTy*>();
149 if (Val.template is<EltTy>())
151 return *Val.template get<VecTy*>();
157 std::enable_if_t<std::is_convertible<ArrayRef<EltTy>,
ArrayRef<U>>::value,
166 if (Val.
isNull())
return true;
167 if (
VecTy *Vec = Val.template dyn_cast<VecTy*>())
175 if (Val.template is<EltTy>())
177 return Val.template get<VecTy*>()->size();
186 if (Val.template is<EltTy>())
189 return Val.template get<VecTy *>()->begin();
193 if (Val.template is<EltTy>())
196 return Val.template get<VecTy *>()->end();
219 assert(!Val.
isNull() &&
"can't index into an empty vector");
220 if (Val.template is<EltTy>()) {
221 assert(
i == 0 &&
"tinyvector index out of range");
222 return Val.template get<EltTy>();
225 assert(
i < Val.template get<VecTy*>()->size() &&
226 "tinyvector index out of range");
227 return (*Val.template get<VecTy*>())[
i];
232 if (Val.template is<EltTy>())
233 return Val.template get<EltTy>();
234 return Val.template get<VecTy*>()->front();
239 if (Val.template is<EltTy>())
240 return Val.template get<EltTy>();
241 return Val.template get<VecTy*>()->back();
253 if (Val.template is<EltTy>()) {
254 EltTy V = Val.template get<EltTy>();
256 Val.template get<VecTy*>()->push_back(V);
260 Val.template get<VecTy*>()->push_back(NewVal);
265 if (Val.template is<EltTy>())
266 Val = (EltTy)
nullptr;
267 else if (
VecTy *Vec = Val.template get<VecTy*>())
273 if (Val.template is<EltTy>()) {
275 }
else if (
VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
283 assert(
I >=
begin() &&
"Iterator to erase is out of bounds.");
284 assert(
I <
end() &&
"Erasing at past-the-end iterator.");
287 if (Val.template is<EltTy>()) {
290 }
else if (
VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
293 return Vec->erase(
I);
299 assert(
S >=
begin() &&
"Range to erase is out of bounds.");
300 assert(
S <=
E &&
"Trying to erase invalid range.");
301 assert(
E <=
end() &&
"Trying to erase past the end.");
303 if (Val.template is<EltTy>()) {
306 }
else if (
VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
307 return Vec->erase(
S,
E);
313 assert(
I >= this->
begin() &&
"Insertion iterator is out of bounds.");
314 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
317 return std::prev(
end());
319 assert(!Val.
isNull() &&
"Null value with non-end insert iterator.");
320 if (Val.template is<EltTy>()) {
321 EltTy V = Val.template get<EltTy>();
328 return Val.template get<VecTy*>()->insert(
I, Elt);
331 template<
typename ItTy>
333 assert(
I >= this->
begin() &&
"Insertion iterator is out of bounds.");
334 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
341 if (std::next(
From) == To) {
347 }
else if (Val.template is<EltTy>()) {
348 EltTy V = Val.template get<EltTy>();
350 Val.template get<VecTy*>()->push_back(V);
352 return Val.template get<VecTy*>()->insert(
begin() + Offset,
From, To);
358 #endif // LLVM_ADT_TINYPTRVECTOR_H