checked_delete with pointer template parameter
I need to free memory from a container with elements of pointers, where the
container value_type is a pointer type. I cannot use the checked_delete
template as it is, as the template parameter is defined without the '*'
pointer.
For example, the following fails (obviously):
typedef std::vector
From: "Craig Henderson"
My existing solution uses a unary functor, as below, but this met with critism on the Boost Developers' list. What would be the 'boost' solution to this problem?
template<typename T> class free_heap_ptr : public std::unary_function
{ public: free_heap_ptr() { } ~free_heap_ptr() { } void operator() (T p) { delete p; } };
I see nothing wrong with your solution (except the redundant constructor and destructor.) On a slightly higher level, the "boost" solution is to not keep raw pointers in a list, but I'm sure you know that.
participants (2)
-
Craig Henderson
-
Peter Dimov