Skip to content

Commit

Permalink
Get rid of QT_STRICT_ITERATORS
Browse files Browse the repository at this point in the history
The concept was a nice idea to avoid accidental detach() calls
in implicitly shared containers, but it conflicts with a C++11
compatible API for them, with signatures for modifying methods
taking a const_iterator as argument and returning an iterator
(e.g. iterator erase(const_iterator)).

Change-Id: Ia33124bedbd260774a0a66f49aedd84e19c9971b
Reviewed-by: Simon Hausmann <[email protected]>
  • Loading branch information
laknoll authored and tronical committed Nov 4, 2019
1 parent ab6affa commit 0645687
Show file tree
Hide file tree
Showing 24 changed files with 15 additions and 165 deletions.
20 changes: 2 additions & 18 deletions src/corelib/tools/qhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,8 @@ class QHash
inline iterator &operator-=(int j) { return *this = *this - j; }
friend inline iterator operator+(int j, iterator k) { return k + j; }

#ifndef QT_STRICT_ITERATORS
public:
inline bool operator==(const const_iterator &o) const
{ return i == o.i; }
inline bool operator!=(const const_iterator &o) const
{ return i != o.i; }
#endif
inline bool operator==(const const_iterator &o) const { return i == o.i; }
inline bool operator!=(const const_iterator &o) const { return i != o.i; }
};
friend class iterator;

Expand All @@ -390,11 +385,7 @@ class QHash
Q_DECL_CONSTEXPR inline const_iterator() : i(nullptr) { }
explicit inline const_iterator(void *node)
: i(reinterpret_cast<QHashData::Node *>(node)) { }
#ifdef QT_STRICT_ITERATORS
explicit inline const_iterator(const iterator &o)
#else
inline const_iterator(const iterator &o)
#endif
{ i = o.i; }

inline const Key &key() const { return concrete(i)->key; }
Expand Down Expand Up @@ -428,13 +419,6 @@ class QHash
inline const_iterator &operator+=(int j) { return *this = *this + j; }
inline const_iterator &operator-=(int j) { return *this = *this - j; }
friend inline const_iterator operator+(int j, const_iterator k) { return k + j; }

// ### Qt 5: not sure this is necessary anymore
#ifdef QT_STRICT_ITERATORS
private:
inline bool operator==(const iterator &o) const { return operator==(const_iterator(o)); }
inline bool operator!=(const iterator &o) const { return operator!=(const_iterator(o)); }
#endif
};
friend class const_iterator;

Expand Down
21 changes: 3 additions & 18 deletions src/corelib/tools/qmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,8 @@ class QMap
inline iterator &operator-=(int j) { return *this = *this - j; }
friend inline iterator operator+(int j, iterator k) { return k + j; }

#ifndef QT_STRICT_ITERATORS
public:
inline bool operator==(const const_iterator &o) const
{ return i == o.i; }
inline bool operator!=(const const_iterator &o) const
{ return i != o.i; }
#endif
inline bool operator==(const const_iterator &o) const { return i == o.i; }
inline bool operator!=(const const_iterator &o) const { return i != o.i; }
friend class QMap<Key, T>;
};
friend class iterator;
Expand All @@ -458,12 +453,7 @@ class QMap

Q_DECL_CONSTEXPR inline const_iterator() : i(nullptr) { }
inline const_iterator(const Node *node) : i(node) { }
#ifdef QT_STRICT_ITERATORS
explicit inline const_iterator(const iterator &o)
#else
inline const_iterator(const iterator &o)
#endif
{ i = o.i; }
inline const_iterator(const iterator &o) { i = o.i; }

inline const Key &key() const { return i->key; }
inline const T &value() const { return i->value; }
Expand Down Expand Up @@ -497,11 +487,6 @@ class QMap
inline const_iterator &operator-=(int j) { return *this = *this - j; }
friend inline const_iterator operator+(int j, const_iterator k) { return k + j; }

#ifdef QT_STRICT_ITERATORS
private:
inline bool operator==(const iterator &o) const { return operator==(const_iterator(o)); }
inline bool operator!=(const iterator &o) const { return operator!=(const_iterator(o)); }
#endif
friend class QMap<Key, T>;
};
friend class const_iterator;
Expand Down
11 changes: 0 additions & 11 deletions src/corelib/tools/qvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ class QVector
typedef typename Data::const_iterator const_iterator;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
#if !defined(QT_STRICT_ITERATORS) || defined(Q_CLANG_QDOC)
inline iterator begin() { detach(); return d->begin(); }
inline const_iterator begin() const noexcept { return d->constBegin(); }
inline const_iterator cbegin() const noexcept { return d->constBegin(); }
Expand All @@ -217,16 +216,6 @@ class QVector
inline const_iterator end() const noexcept { return d->constEnd(); }
inline const_iterator cend() const noexcept { return d->constEnd(); }
inline const_iterator constEnd() const noexcept { return d->constEnd(); }
#else
inline iterator begin(iterator = iterator()) { detach(); return d->begin(); }
inline const_iterator begin(const_iterator = const_iterator()) const noexcept { return d->constBegin(); }
inline const_iterator cbegin(const_iterator = const_iterator()) const noexcept { return d->constBegin(); }
inline const_iterator constBegin(const_iterator = const_iterator()) const noexcept { return d->constBegin(); }
inline iterator end(iterator = iterator()) { detach(); return d->end(); }
inline const_iterator end(const_iterator = const_iterator()) const noexcept { return d->constEnd(); }
inline const_iterator cend(const_iterator = const_iterator()) const noexcept { return d->constEnd(); }
inline const_iterator constEnd(const_iterator = const_iterator()) const noexcept { return d->constEnd(); }
#endif
reverse_iterator rbegin() { return reverse_iterator(end()); }
reverse_iterator rend() { return reverse_iterator(begin()); }
const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); }
Expand Down
7 changes: 0 additions & 7 deletions src/corelib/tools/qvector_msvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,5 @@
# error "This file must be compiled with no precompiled headers"
#endif

// invert the setting of QT_STRICT_ITERATORS, whichever it was
#ifdef QT_STRICT_ITERATORS
# undef QT_STRICT_ITERATORS
#else
# define QT_STRICT_ITERATORS
#endif

// the Q_TEMPLATE_EXTERN at the bottom of qvector.h will do the trick
#include <QtCore/qvector.h>
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ CONFIG += testcase
TARGET = tst_qtconcurrentfilter
QT = core testlib concurrent
SOURCES = tst_qtconcurrentfilter.cpp
DEFINES += QT_STRICT_ITERATORS
DEFINES -= QT_NO_LINKED_LIST
1 change: 0 additions & 1 deletion tests/auto/concurrent/qtconcurrentmap/qtconcurrentmap.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ CONFIG += testcase
TARGET = tst_qtconcurrentmap
QT = core testlib concurrent
SOURCES = tst_qtconcurrentmap.cpp
DEFINES += QT_STRICT_ITERATORS
DEFINES -= QT_NO_LINKED_LIST

# Force C++17 if available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ CONFIG += testcase
TARGET = tst_qtconcurrentmedian
QT = core testlib concurrent
SOURCES = tst_qtconcurrentmedian.cpp
DEFINES += QT_STRICT_ITERATORS
1 change: 0 additions & 1 deletion tests/auto/corelib/thread/qfuture/qfuture.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ CONFIG += testcase
TARGET = tst_qfuture
QT = core core-private testlib
SOURCES = tst_qfuture.cpp
DEFINES += QT_STRICT_ITERATORS
DEFINES -= QT_NO_JAVA_STYLE_ITERATORS
1 change: 0 additions & 1 deletion tests/auto/corelib/thread/qresultstore/qresultstore.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ CONFIG += testcase
TARGET = tst_qresultstore
QT = core-private testlib
SOURCES = tst_qresultstore.cpp
DEFINES += QT_STRICT_ITERATORS
1 change: 0 additions & 1 deletion tests/auto/corelib/tools/collections/collections.pro
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ QT = core testlib

# This test does not work with strict iterators
DEFINES -= QT_NO_LINKED_LIST
DEFINES -= QT_STRICT_ITERATORS
DEFINES -= QT_NO_JAVA_STYLE_ITERATORS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ TARGET = tst_containerapisymmetry
SOURCES += tst_containerapisymmetry.cpp
QT = core testlib

# This test does not work with strict iterators
DEFINES -= QT_STRICT_ITERATORS
DEFINES -= QT_NO_LINKED_LIST

This file was deleted.

This file was deleted.

19 changes: 9 additions & 10 deletions tests/auto/corelib/tools/qmap/tst_qmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1351,17 +1351,16 @@ void tst_QMap::testInsertMultiWithHint()
{
QMap<int, int> map;

typedef QMap<int, int>::const_iterator cite; // Hack since we define QT_STRICT_ITERATORS
map.insertMulti(cite(map.end()), 64, 65);
map.insertMulti(map.end(), 64, 65);
map[128] = 129;
map[256] = 257;
sanityCheckTree(map, __LINE__);

map.insertMulti(cite(map.end()), 512, 513);
map.insertMulti(cite(map.end()), 512, 513 * 2);
map.insertMulti(map.end(), 512, 513);
map.insertMulti(map.end(), 512, 513 * 2);
sanityCheckTree(map, __LINE__);
QCOMPARE(map.size(), 5);
map.insertMulti(cite(map.end()), 256, 258); // wrong hint
map.insertMulti(map.end(), 256, 258); // wrong hint
sanityCheckTree(map, __LINE__);
QCOMPARE(map.size(), 6);

Expand All @@ -1373,23 +1372,23 @@ void tst_QMap::testInsertMultiWithHint()
sanityCheckTree(map, __LINE__);
QCOMPARE(map.size(), 8);

j = map.insertMulti(cite(j), 68, 259);
j = map.insertMulti(j, 68, 259);
sanityCheckTree(map, __LINE__);
QCOMPARE(map.size(), 9);

j = map.insertMulti(cite(j), 67, 67);
j = map.insertMulti(j, 67, 67);
sanityCheckTree(map, __LINE__);
QCOMPARE(map.size(), 10);

i = map.insertMulti(cite(i), 256, 259);
i = map.insertMulti(i, 256, 259);
sanityCheckTree(map, __LINE__);
QCOMPARE(map.size(), 11);

i = map.insertMulti(cite(i), 256, 260);
i = map.insertMulti(i, 256, 260);
sanityCheckTree(map, __LINE__);
QCOMPARE(map.size(), 12);

map.insertMulti(cite(i), 64, 67);
map.insertMulti(i, 64, 67);
sanityCheckTree(map, __LINE__);
QCOMPARE(map.size(), 13);

Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions tests/auto/corelib/tools/qset/tst_qset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
**
****************************************************************************/

//#define QT_STRICT_ITERATORS

#include <QtTest/QtTest>
#include <qset.h>
#include <qdebug.h>
Expand Down

This file was deleted.

4 changes: 0 additions & 4 deletions tests/auto/corelib/tools/tools.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ SUBDIRS=\
containerapisymmetry \
qalgorithms \
qarraydata \
qarraydata_strictiterators \
qbitarray \
qcache \
qcommandlineparser \
Expand All @@ -14,13 +13,11 @@ SUBDIRS=\
qexplicitlyshareddatapointer \
qfreelist \
qhash \
qhash_strictiterators \
qhashfunctions \
qline \
qlinkedlist \
qmakearray \
qmap \
qmap_strictiterators \
qmargins \
qmessageauthenticationcode \
qoffsetstringarray \
Expand All @@ -41,7 +38,6 @@ SUBDIRS=\
qtimeline \
qvarlengtharray \
qvector \
qvector_strictiterators \
qversionnumber

darwin: SUBDIRS += qmacautoreleasepool
69 changes: 0 additions & 69 deletions tests/benchmarks/corelib/tools/qvector/qrawvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,78 +130,9 @@ class QRawVector
bool contains(const T &t) const;
int count(const T &t) const;

#ifdef QT_STRICT_ITERATORS
class iterator {
public:
T *i;
typedef std::random_access_iterator_tag iterator_category;
typedef ptrdiff_t difference_type;
typedef T value_type;
typedef T *pointer;
typedef T &reference;

inline iterator() : i(0) {}
inline iterator(T *n) : i(n) {}
inline iterator(const iterator &o): i(o.i){}
inline T &operator*() const { return *i; }
inline T *operator->() const { return i; }
inline T &operator[](int j) const { return *(i + j); }
inline bool operator==(const iterator &o) const { return i == o.i; }
inline bool operator!=(const iterator &o) const { return i != o.i; }
inline bool operator<(const iterator& other) const { return i < other.i; }
inline bool operator<=(const iterator& other) const { return i <= other.i; }
inline bool operator>(const iterator& other) const { return i > other.i; }
inline bool operator>=(const iterator& other) const { return i >= other.i; }
inline iterator &operator++() { ++i; return *this; }
inline iterator operator++(int) { T *n = i; ++i; return n; }
inline iterator &operator--() { i--; return *this; }
inline iterator operator--(int) { T *n = i; i--; return n; }
inline iterator &operator+=(int j) { i+=j; return *this; }
inline iterator &operator-=(int j) { i-=j; return *this; }
inline iterator operator+(int j) const { return iterator(i+j); }
inline iterator operator-(int j) const { return iterator(i-j); }
inline int operator-(iterator j) const { return i - j.i; }
};
friend class iterator;

class const_iterator {
public:
T *i;
typedef std::random_access_iterator_tag iterator_category;
typedef ptrdiff_t difference_type;
typedef T value_type;
typedef const T *pointer;
typedef const T &reference;

inline const_iterator() : i(0) {}
inline const_iterator(T *n) : i(n) {}
inline const_iterator(const const_iterator &o): i(o.i) {}
inline explicit const_iterator(const iterator &o): i(o.i) {}
inline const T &operator*() const { return *i; }
inline const T *operator->() const { return i; }
inline const T &operator[](int j) const { return *(i + j); }
inline bool operator==(const const_iterator &o) const { return i == o.i; }
inline bool operator!=(const const_iterator &o) const { return i != o.i; }
inline bool operator<(const const_iterator& other) const { return i < other.i; }
inline bool operator<=(const const_iterator& other) const { return i <= other.i; }
inline bool operator>(const const_iterator& other) const { return i > other.i; }
inline bool operator>=(const const_iterator& other) const { return i >= other.i; }
inline const_iterator &operator++() { ++i; return *this; }
inline const_iterator operator++(int) { T *n = i; ++i; return n; }
inline const_iterator &operator--() { i--; return *this; }
inline const_iterator operator--(int) { T *n = i; i--; return n; }
inline const_iterator &operator+=(int j) { i+=j; return *this; }
inline const_iterator &operator-=(int j) { i+=j; return *this; }
inline const_iterator operator+(int j) const { return const_iterator(i+j); }
inline const_iterator operator-(int j) const { return const_iterator(i-j); }
inline int operator-(const_iterator j) const { return i - j.i; }
};
friend class const_iterator;
#else
// STL-style
typedef T *iterator;
typedef const T *const_iterator;
#endif
inline iterator begin() { return m_begin; }
inline const_iterator begin() const { return m_begin; }
inline const_iterator constBegin() const { return m_begin; }
Expand Down
1 change: 0 additions & 1 deletion tests/manual/corelib/tools/qhash/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
****************************************************************************/

#include <QDebug>
//#define QT_STRICT_ITERATORS
#include <QHash>

void testEraseNoError()
Expand Down
3 changes: 1 addition & 2 deletions tests/manual/corelib/tools/qlist/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
**
****************************************************************************/
#include <QDebug>
//#define QT_STRICT_ITERATORS
#include <QVector>
void testErase()
{
Expand Down Expand Up @@ -55,4 +54,4 @@ int main()
// testErase();
testInsert();
return 0;
}
}
1 change: 0 additions & 1 deletion tests/manual/corelib/tools/qset/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
****************************************************************************/

#include <QDebug>
//#define QT_STRICT_ITERATORS
#include <QSet>

void testErase()
Expand Down
1 change: 0 additions & 1 deletion tests/manual/corelib/tools/qvarlengtharray/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
****************************************************************************/

#include <QDebug>
//#define QT_STRICT_ITERATORS
#include <QVarLengthArray>

void testErase()
Expand Down
1 change: 0 additions & 1 deletion tests/manual/corelib/tools/qvector/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
****************************************************************************/

#include <QDebug>
//#define QT_STRICT_ITERATORS
#include <QVector>

void testErase()
Expand Down

0 comments on commit 0645687

Please sign in to comment.