|
From: | Bastiaan Jacques |
Subject: | Re: [Gnash-commit] /srv/bzr/gnash/trunk r9668: Plug leak. |
Date: | Thu, 4 Sep 2008 14:29:24 -0700 (PDT) |
User-agent: | Alpine 1.00 (DEB 882 2007-12-20) |
Then here is a version using boost range, that will work on any kind of container, including a C-style array of pointers. Of course now it becomes impossible to call clear() on the container. :) But I'm not sure that was a good idea to begin with. template<typename Container> void delete_ptr_container(Container& c) { using namespace boost; typedef typename range_value<Container>::type ContainedPtrType; typedef typename remove_pointer<ContainedPtrType>::type ContainedValType; std::for_each (begin(c), end(c), checked_deleter<ContainedValType>()); } Bastiaan On Thu, 4 Sep 2008, Benjamin Wolsey wrote:
How do you like the following: template <typename T> void delete_ptr_vector(std::vector<T*> vec) { std::for_each(vec.begin(), vec.end(), boost::checked_deleter<T>()); vec.clear(); }Generally I like it (although it should of course take the vector by reference), but it only works for vectors, and not other types of container. There also has pointers in queues and lists. bwy
[Prev in Thread] | Current Thread | [Next in Thread] |