9 #ifndef LLVM_ADT_TINYPTRVECTOR_H
10 #define LLVM_ADT_TINYPTRVECTOR_H
18 #include <type_traits>
28 template <
typename EltTy>
46 if (
VecTy *V = Val.template dyn_cast<VecTy*>())
51 if (
VecTy *V = Val.template dyn_cast<VecTy*>())
65 if (Val.template is<EltTy>()) {
69 Val =
new VecTy(*
RHS.Val.template get<VecTy*>());
74 if (
RHS.Val.template is<EltTy>()) {
75 Val.template get<VecTy*>()->clear();
76 Val.template get<VecTy*>()->push_back(
RHS.front());
78 *Val.template get<VecTy*>() = *
RHS.Val.template get<VecTy*>();
84 RHS.Val = (EltTy)
nullptr;
98 if (
VecTy *V = Val.template dyn_cast<VecTy*>()) {
99 if (
RHS.Val.template is<EltTy>()) {
101 V->push_back(
RHS.front());
139 if (Val.template is<EltTy>())
141 return *Val.template get<VecTy*>();
148 if (Val.template is<EltTy>())
150 return *Val.template get<VecTy*>();
156 std::enable_if_t<std::is_convertible<ArrayRef<EltTy>,
ArrayRef<U>>::value,
165 if (Val.
isNull())
return true;
166 if (
VecTy *Vec = Val.template dyn_cast<VecTy*>())
174 if (Val.template is<EltTy>())
176 return Val.template get<VecTy*>()->size();
185 if (Val.template is<EltTy>())
188 return Val.template get<VecTy *>()->begin();
192 if (Val.template is<EltTy>())
195 return Val.template get<VecTy *>()->end();
218 assert(!Val.
isNull() &&
"can't index into an empty vector");
219 if (Val.template is<EltTy>()) {
220 assert(
i == 0 &&
"tinyvector index out of range");
221 return Val.template get<EltTy>();
224 assert(
i < Val.template get<VecTy*>()->size() &&
225 "tinyvector index out of range");
226 return (*Val.template get<VecTy*>())[
i];
231 if (Val.template is<EltTy>())
232 return Val.template get<EltTy>();
233 return Val.template get<VecTy*>()->front();
238 if (Val.template is<EltTy>())
239 return Val.template get<EltTy>();
240 return Val.template get<VecTy*>()->back();
252 if (Val.template is<EltTy>()) {
253 EltTy V = Val.template get<EltTy>();
255 Val.template get<VecTy*>()->push_back(V);
259 Val.template get<VecTy*>()->push_back(NewVal);
264 if (Val.template is<EltTy>())
265 Val = (EltTy)
nullptr;
266 else if (
VecTy *Vec = Val.template get<VecTy*>())
272 if (Val.template is<EltTy>()) {
274 }
else if (
VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
282 assert(
I >=
begin() &&
"Iterator to erase is out of bounds.");
283 assert(
I <
end() &&
"Erasing at past-the-end iterator.");
286 if (Val.template is<EltTy>()) {
289 }
else if (
VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
292 return Vec->erase(
I);
298 assert(
S >=
begin() &&
"Range to erase is out of bounds.");
299 assert(
S <=
E &&
"Trying to erase invalid range.");
300 assert(
E <=
end() &&
"Trying to erase past the end.");
302 if (Val.template is<EltTy>()) {
305 }
else if (
VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
306 return Vec->erase(
S,
E);
312 assert(
I >= this->
begin() &&
"Insertion iterator is out of bounds.");
313 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
316 return std::prev(
end());
318 assert(!Val.
isNull() &&
"Null value with non-end insert iterator.");
319 if (Val.template is<EltTy>()) {
320 EltTy V = Val.template get<EltTy>();
327 return Val.template get<VecTy*>()->insert(
I, Elt);
330 template<
typename ItTy>
332 assert(
I >= this->
begin() &&
"Insertion iterator is out of bounds.");
333 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
340 if (std::next(
From) == To) {
346 }
else if (Val.template is<EltTy>()) {
347 EltTy V = Val.template get<EltTy>();
349 Val.template get<VecTy*>()->push_back(V);
357 #endif // LLVM_ADT_TINYPTRVECTOR_H