Is there a standard or recommended way of handling deletion and removal
of objects in STL. I have loads of list of classes by pointer.
e.g.
If I have a list<int*>, how should I delete the objects and clear the
list.
From looking at this I see it can be done with a functor, my plain
iteration or by defining a template function.
my current idea is something like this - is it recommended ?:
template<typename T>
void clear_and_delete1(T& t) {
T::iterator it = t.begin(), end = t.end();
while(it != end)
delete (*(it++));
t.clear();
}
template<typename T>
void clear_and_delete2(T& t) {
T::iterator it = t.begin(), end = t.end();
while(it != end)
delete (**(it++));
t.clear();
}