[llvm] r269710 - Add missing TinyPtrVector functionality: reverse iterators and conversion of

Richard Smith via llvm-commits llvm-commits at lists.llvm.org
Mon May 16 14:45:59 PDT 2016


Author: rsmith
Date: Mon May 16 16:45:58 2016
New Revision: 269710

URL: http://llvm.org/viewvc/llvm-project?rev=269710&view=rev
Log:
Add missing TinyPtrVector functionality: reverse iterators and conversion of
TinyPtrVector<T*> to ArrayRef<const T*>.

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=269710&r1=269709&r2=269710&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/TinyPtrVector.h (original)
+++ llvm/trunk/include/llvm/ADT/TinyPtrVector.h Mon May 16 16:45:58 2016
@@ -125,6 +125,15 @@ public:
     return *Val.template get<VecTy*>();
   }
 
+  // Implicit conversion to ArrayRef<U> if EltTy* implicitly converts to U*.
+  template<typename U,
+           typename std::enable_if<
+               std::is_convertible<ArrayRef<EltTy>, ArrayRef<U>>::value,
+               bool>::type = false>
+  operator ArrayRef<U>() const {
+    return operator ArrayRef<EltTy>();
+  }
+
   bool empty() const {
     // This vector can be empty if it contains no element, or if it
     // contains a pointer to an empty vector.
@@ -142,8 +151,10 @@ public:
     return Val.template get<VecTy*>()->size();
   }
 
-  typedef const EltTy *const_iterator;
   typedef EltTy *iterator;
+  typedef const EltTy *const_iterator;
+  typedef std::reverse_iterator<iterator> reverse_iterator;
+  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
 
   iterator begin() {
     if (Val.template is<EltTy>())
@@ -166,6 +177,15 @@ public:
     return (const_iterator)const_cast<TinyPtrVector*>(this)->end();
   }
 
+  reverse_iterator rbegin() { return reverse_iterator(end()); }
+  reverse_iterator rend() { return reverse_iterator(begin()); }
+  const_reverse_iterator rbegin() const {
+    return const_reverse_iterator(end());
+  }
+  const_reverse_iterator rend() const {
+    return const_reverse_iterator(begin());
+  }
+
   EltTy operator[](unsigned i) const {
     assert(!Val.isNull() && "can't index into an empty vector");
     if (EltTy V = Val.template dyn_cast<EltTy>()) {




More information about the llvm-commits mailing list