Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any standard delete functor?

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?

like image 853
fredoverflow Avatar asked Apr 27 '10 19:04

fredoverflow


2 Answers

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.

like image 84
James McNellis Avatar answered Nov 06 '22 21:11

James McNellis


Boost.Lambda has delete_ptr and delete_array

like image 2
Éric Malenfant Avatar answered Nov 06 '22 22:11

Éric Malenfant