views:

141

answers:

2

I am looking for a functor that deletes its argument:

template<class T>
struct delete_functor
{
    void operator()(T* p)
    {
        delete p;
    }
};

Is there something like this in std, tr1 or boost?

+6  A: 

C++0x will add std::default_delete to the standard library to support std::unique_ptr.

It has effectively the same functionality as your delete_functor, but is also specialized to call delete[] for array type objects.

James McNellis
Thanks, works like a charm!
FredOverflow
+2  A: 

Boost.Lambda has delete_ptr and delete_array

Éric Malenfant
I can't get this to work. What header do I have to include?
FredOverflow
`#include <boost/lambda/construct.hpp>`
Éric Malenfant