From 8a2341f97661eeafdbbc9e1c4d3fbb98538ce92a Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Fri, 6 Jul 2018 10:56:08 +1000 Subject: [PATCH] Bug 1473771 - Part 2: Make LinkedList::Iterator work when element type inherits from multiple LinkedListElements. r=Waldo MozReview-Commit-ID: 9dNTsSNyIYK --HG-- extra : rebase_source : 60de5392ebf857d71e09a1bc7a68cc19edd66263 --- mfbt/LinkedList.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/mfbt/LinkedList.h b/mfbt/LinkedList.h index b6c01813709a..c299ec6fcaef 100644 --- a/mfbt/LinkedList.h +++ b/mfbt/LinkedList.h @@ -411,11 +411,13 @@ private: typedef typename Traits::ConstRawType ConstRawType; typedef typename Traits::ClientType ClientType; typedef typename Traits::ConstClientType ConstClientType; + typedef LinkedListElement* ElementType; + typedef const LinkedListElement* ConstElementType; LinkedListElement sentinel; public: - template + template class Iterator { Type mCurrent; @@ -427,11 +429,11 @@ public: } const Iterator& operator++() { - mCurrent = mCurrent->getNext(); + mCurrent = static_cast(mCurrent)->getNext(); return *this; } - bool operator!=(const Iterator& aOther) const { + bool operator!=(const Iterator& aOther) const { return mCurrent != aOther.mCurrent; } }; @@ -536,17 +538,17 @@ public: * * for (MyElementType* elt : myList) { ... } */ - Iterator begin() { - return Iterator(getFirst()); + Iterator begin() { + return Iterator(getFirst()); } - Iterator begin() const { - return Iterator(getFirst()); + Iterator begin() const { + return Iterator(getFirst()); } - Iterator end() { - return Iterator(nullptr); + Iterator end() { + return Iterator(nullptr); } - Iterator end() const { - return Iterator(nullptr); + Iterator end() const { + return Iterator(nullptr); } /*