Thanks again Peter. The first solution was actually the one I was trying to compile but was getting linker errors trying to find the body of the concrete function (using MSVC 7) - wierd. Peter Dimov wrote:
From: "Mark Snelling" [...]
std::list
I can call the for_each algorithm on this list using my function above:
std::for_each(mylist.begin(), mylist.end(), &deleter);
and it will delete all of the objects pointed to in the list. Is it possible to convert deleter into a templated function:
template<class T> void deleter(T* t) { delete t; }
and pass that into the for_each algorithm?
Yes. You can use
std::for_each(mylist.begin(), mylist.end(), &deleter<Object>);
If this doesn't work, try
#include
std::for_each(mylist.begin(), mylist.end(), boost::checked_deleter<Object>());
An alternative is to convert mylist to
std::list< boost::shared_ptr<Object > mylist;
and let it worry about the lifetime of the objects.
Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/