Suppose I have a std::vector
(for performance reasons I have pointers not actual Obj
s).
I populate it with obj.push
for_each
needs a function pointer or function object. For memory deallocation you could try &::operator delete
, which would take the address of the function that deallocates memory. However, when you use the delete statement the compiler calls the destructor before calling operator delete(void*)
so cleanup is actually not part of the operator delete(void*)
function.
Use a functor ala GMan's answer.