allow TinyPtrVector to implicitly convert to ArrayRef.
authorChris Lattner <sabre@nondot.org>
Tue, 6 Dec 2011 02:00:33 +0000 (02:00 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 6 Dec 2011 02:00:33 +0000 (02:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145898 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/TinyPtrVector.h

index ee86d8bdf70f529e895a82986aa32dfe95160db3..e27dd4b78507cd3cc50930d4326ee5e08f0afe4d 100644 (file)
@@ -37,6 +37,15 @@ public:
       delete V;
   }
   
+  // implicit conversion operator to ArrayRef.
+  operator ArrayRef<EltTy>() const {
+    if (Val.isNull())
+      return ArrayRef<EltTy>();
+    if (Val.template is<EltTy>())
+      return *Val.template getAddrOf<EltTy>();
+    return *Val.template get<VecTy*>();
+  }
+  
   bool empty() const {
     // This vector can be empty if it contains no element, or if it
     // contains a pointer to an empty vector.