We are not allowed to use boost in my company, and we do not use C ++ 11, so I use this:
namespace { // - for use to deletion: // std::vector<int*> foobar; // std::for_each(foobar.begin(), fooabr.end(), del_fun<T>()); template<class _Type> struct del_fun_t: public unary_function<_Type*, void> { void operator()(_Type* __ptr) { delete __ptr; } }; template<class _Type> del_fun_t<_Type> del_fun() { return del_fun_t<_Type>(); }; };
I think what you are looking for.
You can also recreate it as dtor_fun_t and replace "delete _ptr;" by "_ptr-> ~ _Type ();" to call only dtoro. This will be the case when, for example, you used the memory manager and placement.
Blakbat
source share