зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1121269 - Add an AutoCleanLinkedList template that removes and deletes elements upon destruction. r=Waldo
This commit is contained in:
Родитель
693a41b39b
Коммит
c18398b98d
|
@ -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 */
|
||||
|
|
Загрузка…
Ссылка в новой задаче