[llvm-commits] [llvm] r145898 - /llvm/trunk/include/llvm/ADT/TinyPtrVector.h

Chris Lattner sabre at nondot.org
Mon Dec 5 18:00:33 PST 2011


Author: lattner
Date: Mon Dec  5 20:00:33 2011
New Revision: 145898

URL: http://llvm.org/viewvc/llvm-project?rev=145898&view=rev
Log:
allow TinyPtrVector to implicitly convert to ArrayRef.

Modified:
    llvm/trunk/include/llvm/ADT/TinyPtrVector.h

Modified: llvm/trunk/include/llvm/ADT/TinyPtrVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/TinyPtrVector.h?rev=145898&r1=145897&r2=145898&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/TinyPtrVector.h (original)
+++ llvm/trunk/include/llvm/ADT/TinyPtrVector.h Mon Dec  5 20:00:33 2011
@@ -37,6 +37,15 @@
       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.





More information about the llvm-commits mailing list