You can use for_each
:
std::vector v;
template
struct deleter : std::unary_function
{
void operator() (const T *ptr) const
{
delete ptr;
}
};
// call deleter for each element , freeing them
std::for_each (v.begin (), v.end (), deleter ());
v.clear ();