mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1121269 - Add an AutoCleanLinkedList template that removes and deletes elements upon destruction. r=Waldo
This commit is contained in:
parent
fe917e8ec3
commit
837ac3f6f8
@ -55,6 +55,10 @@
|
||||
* }
|
||||
* };
|
||||
*
|
||||
* Additionally, the class AutoCleanLinkedList<T> is a LinkedList<T> that will
|
||||
* remove and delete each element still within itself upon destruction. Note
|
||||
* that because each element is deleted, elements must have been allocated
|
||||
* using |new|.
|
||||
*/
|
||||
|
||||
#ifndef mozilla_LinkedList_h
|
||||
@ -478,6 +482,18 @@ private:
|
||||
LinkedList(const LinkedList<T>& aOther) = delete;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class AutoCleanLinkedList : public LinkedList<T>
|
||||
{
|
||||
public:
|
||||
~AutoCleanLinkedList()
|
||||
{
|
||||
while (T* element = this->popFirst()) {
|
||||
delete element;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} /* namespace mozilla */
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
Loading…
Reference in New Issue
Block a user