From 6ae4bc89582ba23712149c3070bd5f806b8f3f2a Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Thu, 24 Mar 2016 20:25:51 +0000 Subject: [PATCH] [ADT] C++11ify SmallVector::erase's arguments from iterator to const_iterator llvm-svn: 264330 --- llvm/include/llvm/ADT/SmallVector.h | 12 ++++++++++-- llvm/unittests/ADT/SmallVectorTest.cpp | 6 ++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h index d1062ac..aa83e3f 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h @@ -356,6 +356,7 @@ class SmallVectorImpl : public SmallVectorTemplateBase::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(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(CS); + iterator E = const_cast(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."); diff --git a/llvm/unittests/ADT/SmallVectorTest.cpp b/llvm/unittests/ADT/SmallVectorTest.cpp index 46f7021..7367ad4 100644 --- a/llvm/unittests/ADT/SmallVectorTest.cpp +++ b/llvm/unittests/ADT/SmallVectorTest.cpp @@ -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); } -- 2.7.4