From 195977f6e9e21e23a9ae3a13c9bbcea38eb5387b Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Fri, 18 Oct 2019 16:10:12 +0200 Subject: 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 --- src/qml/compiler/qqmlirbuilder.cpp | 8 +++++--- src/qml/compiler/qqmlirbuilder_p.h | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) (limited to 'src/qml/compiler') 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; -- cgit v1.2.3