[llvm] r264330 - [ADT] C++11ify SmallVector::erase's arguments from iterator to const_iterator

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 24 13:25:51 PDT 2016


Author: dblaikie
Date: Thu Mar 24 15:25:51 2016
New Revision: 264330

URL: http://llvm.org/viewvc/llvm-project?rev=264330&view=rev
Log:
[ADT] C++11ify SmallVector::erase's arguments from iterator to const_iterator

Modified:
    llvm/trunk/include/llvm/ADT/SmallVector.h
    llvm/trunk/unittests/ADT/SmallVectorTest.cpp

Modified: llvm/trunk/include/llvm/ADT/SmallVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?rev=264330&r1=264329&r2=264330&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SmallVector.h (original)
+++ llvm/trunk/include/llvm/ADT/SmallVector.h Thu Mar 24 15:25:51 2016
@@ -356,6 +356,7 @@ class SmallVectorImpl : public SmallVect
   SmallVectorImpl(const SmallVectorImpl&) = delete;
 public:
   typedef typename SuperClass::iterator iterator;
+  typedef typename SuperClass::const_iterator const_iterator;
   typedef typename SuperClass::size_type size_type;
 
 protected:
@@ -459,7 +460,10 @@ public:
     append(IL);
   }
 
-  iterator erase(iterator I) {
+  iterator erase(const_iterator CI) {
+    // Just cast away constness because this is a non-const member function.
+    iterator I = const_cast<iterator>(CI);
+
     assert(I >= this->begin() && "Iterator to erase is out of bounds.");
     assert(I < this->end() && "Erasing at past-the-end iterator.");
 
@@ -471,7 +475,11 @@ public:
     return(N);
   }
 
-  iterator erase(iterator S, iterator E) {
+  iterator erase(const_iterator CS, const_iterator CE) {
+    // Just cast away constness because this is a non-const member function.
+    iterator S = const_cast<iterator>(CS);
+    iterator E = const_cast<iterator>(CE);
+
     assert(S >= this->begin() && "Range to erase is out of bounds.");
     assert(S <= E && "Trying to erase invalid range.");
     assert(E <= this->end() && "Trying to erase past the end.");

Modified: llvm/trunk/unittests/ADT/SmallVectorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/SmallVectorTest.cpp?rev=264330&r1=264329&r2=264330&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/SmallVectorTest.cpp (original)
+++ llvm/trunk/unittests/ADT/SmallVectorTest.cpp Thu Mar 24 15:25:51 2016
@@ -459,7 +459,8 @@ TYPED_TEST(SmallVectorTest, EraseTest) {
   SCOPED_TRACE("EraseTest");
 
   this->makeSequence(this->theVector, 1, 3);
-  this->theVector.erase(this->theVector.begin());
+  const auto &theConstVector = this->theVector;
+  this->theVector.erase(theConstVector.begin());
   this->assertValuesInOrder(this->theVector, 2u, 2, 3);
 }
 
@@ -468,7 +469,8 @@ TYPED_TEST(SmallVectorTest, EraseRangeTe
   SCOPED_TRACE("EraseRangeTest");
 
   this->makeSequence(this->theVector, 1, 3);
-  this->theVector.erase(this->theVector.begin(), this->theVector.begin() + 2);
+  const auto &theConstVector = this->theVector;
+  this->theVector.erase(theConstVector.begin(), theConstVector.begin() + 2);
   this->assertValuesInOrder(this->theVector, 1u, 3);
 }
 




More information about the llvm-commits mailing list