From c2f10f915fd6fa4d38c83a4c8b0e1c63a254643a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 24 May 2012 08:26:46 +0200 Subject: QVarLengthArray: C++11-ify insert/erase signatures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In C++11, container insert and erase operations take const_iterators instead of iterators. This is a bug fix compared to C++98, where the mere lookup step of a lookup-or-insert operation had to be done using (mutable) iterators, which is particularly worrisome for Qt containers that are implicitly shared, because of the unneeded detach in the positive case. QVarLengthArray is not implicitly shared, but for consistency, the signatures should be changed here, too. The reason this commit contains only the change to QVarLengthArray is that this is by far the easiest container. The implictly shared containers are harder, because detaching invalidates other iterators (more than the sister STL container would). Change-Id: Ib3d98360bfe376b782b9d1283c5fa3555e8a719e Reviewed-by: João Abecasis Reviewed-by: Thiago Macieira --- src/corelib/tools/qvarlengtharray.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/corelib/tools/qvarlengtharray.h') diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index 58b26be4a9..ba24541d2d 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -167,10 +167,10 @@ public: inline const_iterator end() const { return ptr + s; } inline const_iterator cend() const { return ptr + s; } inline const_iterator constEnd() const { return ptr + s; } - iterator insert(iterator before, int n, const T &x); - inline iterator insert(iterator before, const T &x) { return insert(before, 1, x); } - iterator erase(iterator begin, iterator end); - inline iterator erase(iterator pos) { return erase(pos, pos+1); } + iterator insert(const_iterator before, int n, const T &x); + inline iterator insert(const_iterator before, const T &x) { return insert(before, 1, x); } + iterator erase(const_iterator begin, const_iterator end); + inline iterator erase(const_iterator pos) { return erase(pos, pos+1); } private: friend class QPodList; @@ -338,7 +338,7 @@ inline void QVarLengthArray::replace(int i, const T &t) template -Q_OUTOFLINE_TEMPLATE typename QVarLengthArray::iterator QVarLengthArray::insert(iterator before, size_type n, const T &t) +Q_OUTOFLINE_TEMPLATE typename QVarLengthArray::iterator QVarLengthArray::insert(const_iterator before, size_type n, const T &t) { int offset = int(before - ptr); if (n != 0) { @@ -365,7 +365,7 @@ Q_OUTOFLINE_TEMPLATE typename QVarLengthArray::iterator QVarLengthA } template -Q_OUTOFLINE_TEMPLATE typename QVarLengthArray::iterator QVarLengthArray::erase(iterator abegin, iterator aend) +Q_OUTOFLINE_TEMPLATE typename QVarLengthArray::iterator QVarLengthArray::erase(const_iterator abegin, const_iterator aend) { int f = int(abegin - ptr); int l = int(aend - ptr); -- cgit v1.2.3