[TinyPtrVector] Add erase method and const-goodness.
llvm-svn: 152107
This commit is contained in:
parent
3023bc32f0
commit
3031e1c1cf
|
@ -63,8 +63,10 @@ public:
|
||||||
return Val.template get<VecTy*>()->size();
|
return Val.template get<VecTy*>()->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef const EltTy *iterator;
|
typedef const EltTy *const const_iterator;
|
||||||
iterator begin() const {
|
typedef EltTy *iterator;
|
||||||
|
|
||||||
|
iterator begin() {
|
||||||
if (empty())
|
if (empty())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -74,7 +76,7 @@ public:
|
||||||
return Val.template get<VecTy *>()->begin();
|
return Val.template get<VecTy *>()->begin();
|
||||||
|
|
||||||
}
|
}
|
||||||
iterator end() const {
|
iterator end() {
|
||||||
if (empty())
|
if (empty())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -84,6 +86,13 @@ public:
|
||||||
return Val.template get<VecTy *>()->end();
|
return Val.template get<VecTy *>()->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const_iterator begin() const {
|
||||||
|
return (const_iterator)const_cast<TinyPtrVector*>(this)->begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
const_iterator end() const {
|
||||||
|
return (const_iterator)const_cast<TinyPtrVector*>(this)->end();
|
||||||
|
}
|
||||||
|
|
||||||
EltTy operator[](unsigned i) const {
|
EltTy operator[](unsigned i) const {
|
||||||
assert(!Val.isNull() && "can't index into an empty vector");
|
assert(!Val.isNull() && "can't index into an empty vector");
|
||||||
|
@ -134,6 +143,20 @@ public:
|
||||||
// Otherwise, we're already empty.
|
// Otherwise, we're already empty.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iterator erase(iterator I) {
|
||||||
|
// If we have a single value, convert to empty.
|
||||||
|
if (Val.template is<EltTy>()) {
|
||||||
|
if (I == begin())
|
||||||
|
Val = (EltTy)0;
|
||||||
|
} else if (VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
|
||||||
|
// multiple items in a vector; just do the erase, there is no
|
||||||
|
// benefit to collapsing back to a pointer
|
||||||
|
return Vec->erase(I);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void operator=(const TinyPtrVector&); // NOT IMPLEMENTED YET.
|
void operator=(const TinyPtrVector&); // NOT IMPLEMENTED YET.
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue