-
delete functor
One way to write a delete functor to delete all pointers in a container is:
Code:
template<typename T>
struct Deleter : public std::unary_function<const T *, void>
{
void operator()(const T *Object) const
{
delete Object;
}
};
Now Im wondering if the following is a correct safe delete functor, I'm talking specifically about the pointer reference. Also is the first unary_function template paramater correct? (const T *&)
Code:
template<typename T>
struct SafeDeleter : public std::unary_function<const T *&, void>
{
void operator()(const T *&Object) const
{
delete Object;
Object = NULL;
}
};
-
o_O
Why? Why not just use a smart pointer? (You just can't use `std::auto_ptr<???>'.)
A reference of a pointer to a constant value is not the same as a reference to a pointer to a mutable value.
Do you really want two distinct deleter functions?
Or one that behaves differently depending on the mutability of the reference?
It seems like a tremendously bad idea.
Soma
-
I second smart pointers, but this seems OK too (if you don't have boost/compiler supporting C++0x features).