mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1212624 - Implement range-based iteration for LinkedList, r=Waldo
This commit is contained in:
parent
980ee26e3e
commit
6019468a19
@ -299,6 +299,26 @@ private:
|
||||
LinkedListElement<T> sentinel;
|
||||
|
||||
public:
|
||||
class Iterator {
|
||||
T* mCurrent;
|
||||
|
||||
public:
|
||||
explicit Iterator(T* aCurrent) : mCurrent(aCurrent) {}
|
||||
|
||||
T* operator *() const {
|
||||
return mCurrent;
|
||||
}
|
||||
|
||||
const Iterator& operator++() {
|
||||
mCurrent = mCurrent->getNext();
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator!=(Iterator& aOther) const {
|
||||
return mCurrent != aOther.mCurrent;
|
||||
}
|
||||
};
|
||||
|
||||
LinkedList() : sentinel(LinkedListElement<T>::NODE_KIND_SENTINEL) { }
|
||||
|
||||
LinkedList(LinkedList<T>&& aOther)
|
||||
@ -383,6 +403,18 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Allow range-based iteration:
|
||||
*
|
||||
* for (MyElementType* elt : myList) { ... }
|
||||
*/
|
||||
Iterator begin() {
|
||||
return Iterator(getFirst());
|
||||
}
|
||||
Iterator end() {
|
||||
return Iterator(nullptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Measures the memory consumption of the list excluding |this|. Note that
|
||||
* it only measures the list elements themselves. If the list elements
|
||||
|
Loading…
Reference in New Issue
Block a user