[ADT] C++11ify SmallVector::erase's arguments from iterator to const_iterator
authorDavid Blaikie <dblaikie@gmail.com>
Thu, 24 Mar 2016 20:25:51 +0000 (20:25 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Thu, 24 Mar 2016 20:25:51 +0000 (20:25 +0000)
llvm-svn: 264330

llvm/include/llvm/ADT/SmallVector.h
llvm/unittests/ADT/SmallVectorTest.cpp

index d1062ac..aa83e3f 100644 (file)
@@ -356,6 +356,7 @@ class SmallVectorImpl : public SmallVectorTemplateBase<T, isPodLike<T>::value> {
   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.");
index 46f7021..7367ad4 100644 (file)
@@ -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, EraseRangeTest) {
   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);
 }