diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-10-18 16:10:12 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2019-10-18 14:24:31 +0000 |
commit | 195977f6e9e21e23a9ae3a13c9bbcea38eb5387b (patch) | |
tree | b7b7f885ce562c07ece82be2aff93f7dcc0650f2 /src/qml/compiler | |
parent | 9a59596ac02999ee068023d1d8cc779539eee491 (diff) |
QQmlIRBuilder: Turn Iterator into a iterator
The iterator class was missing the required typedefs which are expected
of iterators to support standard algorithms.
Also demonstrate that we can now use standard algorithms on the
containers by using find_if.
Change-Id: Ia03dee4cb89731f407393c340606c3d94f3edb9d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/compiler')
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 8 | ||||
-rw-r--r-- | src/qml/compiler/qqmlirbuilder_p.h | 18 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index 940d61ba97..9623d2ed58 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -250,9 +250,11 @@ QString Object::appendAlias(Alias *alias, const QString &aliasName, bool isDefau if (!target) target = this; - for (Alias *p = target->aliases->first; p; p = p->next) - if (p->nameIndex == alias->nameIndex) - return tr("Duplicate alias name"); + auto aliasWithSameName = std::find_if(target->aliases->begin(), target->aliases->end(), [&alias](const Alias &targetAlias){ + return targetAlias.nameIndex == alias->nameIndex; + }); + if (aliasWithSameName != target->aliases->end()) + return tr("Duplicate alias name"); if (aliasName.constData()->isUpper()) return tr("Alias names cannot begin with an upper case letter"); diff --git a/src/qml/compiler/qqmlirbuilder_p.h b/src/qml/compiler/qqmlirbuilder_p.h index 4279f5b768..ab0ddf6ef8 100644 --- a/src/qml/compiler/qqmlirbuilder_p.h +++ b/src/qml/compiler/qqmlirbuilder_p.h @@ -158,6 +158,13 @@ struct PoolList } struct Iterator { + // turn Iterator into a proper iterator + using iterator_category = std::forward_iterator_tag; + using value_type = T; + using difference_type = ptrdiff_t; + using pointer = T *; + using reference = T &; + T *ptr; explicit Iterator(T *p) : ptr(p) {} @@ -178,8 +185,15 @@ struct PoolList return *ptr; } - void operator++() { + Iterator& operator++() { ptr = ptr->next; + return *this; + } + + Iterator operator++(int) { + Iterator that {ptr}; + ptr = ptr->next; + return that; } bool operator==(const Iterator &rhs) const { @@ -193,6 +207,8 @@ struct PoolList Iterator begin() { return Iterator(first); } Iterator end() { return Iterator(nullptr); } + + using iterator = Iterator; }; struct Object; |