#ifndef LLVM_ADT_TINYPTRVECTOR_H
#define LLVM_ADT_TINYPTRVECTOR_H
+#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/PointerUnion.h"
+#include "llvm/Support/Compiler.h"
namespace llvm {
if (VecTy *V = Val.template dyn_cast<VecTy*>())
Val = new VecTy(*V);
}
+#if LLVM_USE_RVALUE_REFERENCES
+ TinyPtrVector(TinyPtrVector &&RHS) : Val(RHS.Val) {
+ RHS.Val = (EltTy)0;
+ }
+#endif
~TinyPtrVector() {
if (VecTy *V = Val.template dyn_cast<VecTy*>())
delete V;
if (Val.isNull())
return ArrayRef<EltTy>();
if (Val.template is<EltTy>())
- return *Val.template getAddrOf<EltTy>();
+ return *Val.getAddrOfPtr1();
return *Val.template get<VecTy*>();
}
return Val.template get<VecTy*>()->size();
}
- typedef const EltTy *iterator;
- iterator begin() const {
+ typedef const EltTy *const_iterator;
+ typedef EltTy *iterator;
+
+ iterator begin() {
if (empty())
return 0;
return Val.template get<VecTy *>()->begin();
}
- iterator end() const {
+ iterator end() {
if (empty())
return 0;
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 {
assert(!Val.isNull() && "can't index into an empty vector");
if (EltTy V = Val.template dyn_cast<EltTy>()) {
return Val.template get<VecTy*>()->front();
}
+ EltTy back() const {
+ assert(!empty() && "vector empty");
+ if (EltTy V = Val.template dyn_cast<EltTy>())
+ return V;
+ return Val.template get<VecTy*>()->back();
+ }
+
+
void push_back(EltTy NewVal) {
assert(NewVal != 0 && "Can't add a null value");
Val.template get<VecTy*>()->push_back(NewVal);
}
+ void pop_back() {
+ // If we have a single value, convert to empty.
+ if (Val.template is<EltTy>())
+ Val = (EltTy)0;
+ else if (VecTy *Vec = Val.template get<VecTy*>())
+ Vec->pop_back();
+ }
+
+
void clear() {
// If we have a single value, convert to empty.
if (Val.template is<EltTy>()) {
}
// 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:
void operator=(const TinyPtrVector&); // NOT IMPLEMENTED YET.
+#if LLVM_USE_RVALUE_REFERENCES
+ void operator=(TinyPtrVector&&); // NOT IMPLEMENTED YET.
+#endif
};
} // end namespace llvm