summaryrefslogtreecommitdiff
path: root/include/llvm/ADT/TinyPtrVector.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2012-05-28 01:29:59 +0000
committerChris Lattner <sabre@nondot.org>2012-05-28 01:29:59 +0000
commit2edc74aa1fb541253f4286a70194960dab69506b (patch)
tree685cfece46f9ebb3826f75a44bfa20e537f8458d /include/llvm/ADT/TinyPtrVector.h
parent86208903cb3b693b26e144b8c5c7a0ab6a9a45c6 (diff)
downloadllvm-2edc74aa1fb541253f4286a70194960dab69506b.tar.gz
llvm-2edc74aa1fb541253f4286a70194960dab69506b.tar.bz2
llvm-2edc74aa1fb541253f4286a70194960dab69506b.tar.xz
add some helper methods to make the type more uniform.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157554 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/TinyPtrVector.h')
-rw-r--r--include/llvm/ADT/TinyPtrVector.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/llvm/ADT/TinyPtrVector.h b/include/llvm/ADT/TinyPtrVector.h
index f9b7d559c3..8f3925c9c5 100644
--- a/include/llvm/ADT/TinyPtrVector.h
+++ b/include/llvm/ADT/TinyPtrVector.h
@@ -120,6 +120,14 @@ public:
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");
@@ -139,6 +147,15 @@ public:
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>()) {