add iteration support to TinyPtrVector for clang's use.
authorChris Lattner <sabre@nondot.org>
Mon, 18 Jul 2011 01:53:11 +0000 (01:53 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 18 Jul 2011 01:53:11 +0000 (01:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135367 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/TinyPtrVector.h

index 8fbd6f61e27353f6d1a99324fe0d4b90e916c694..8fcd2f33f523f30fd7454127e42259c288d8f747 100644 (file)
@@ -58,6 +58,28 @@ public:
     return Val. template get<VecTy*>()->size();
   }
   
+  typedef const EltTy *iterator;
+  iterator begin() const {
+    if (empty())
+      return 0;
+    
+    if (Val.template is<EltTy>())
+      return Val.template getAddrOf<EltTy>();
+    
+    return Val.template get<VecTy *>()->begin();
+
+  }
+  iterator end() const {
+    if (empty())
+      return 0;
+    
+    if (Val.template is<EltTy>())
+      return begin() + 1;
+    
+    return Val.template get<VecTy *>()->end();
+  }
+
+  
   EltTy operator[](unsigned i) const {
     assert(!Val.isNull() && "can't index into an empty vector");
     if (EltTy V = Val.template dyn_cast<EltTy>()) {