From aa8bff87ee2cb2cfac275031c462d3d76702fdaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 9 May 2008 13:08:59 +0000 Subject: [PATCH] Followed Ingo's suggestion, and made StackDeleter an AutoDeleter specialization. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25395 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/util/Stack.h | 35 ++++++++++++++++------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/headers/private/kernel/util/Stack.h b/headers/private/kernel/util/Stack.h index 855db1fd45..d32a8023c6 100644 --- a/headers/private/kernel/util/Stack.h +++ b/headers/private/kernel/util/Stack.h @@ -10,6 +10,8 @@ #include +#include + template class Stack { public: @@ -76,33 +78,34 @@ template class Stack { int32 fMax; }; -template class StackDeleter { -public: - StackDeleter(Stack* stack) - : fStack(stack) - { - } - ~StackDeleter() +template class StackDelete { +public: + inline void operator()(Stack* stack) { - if (fStack == NULL) + if (stack == NULL) return; - + T item; - while (fStack->Pop(&item)) { + while (stack->Pop(&item)) { delete item; } - - delete fStack; + + delete stack; } +}; - void Detach() +template class StackDeleter + : public BPrivate::AutoDeleter, StackDelete > { +public: + StackDeleter() { - fStack = NULL; } -private: - Stack* fStack; + StackDeleter(Stack* stack) + : BPrivate::AutoDeleter, StackDelete >(stack) + { + } }; #endif /* KERNEL_UTIL_STACK_H */