Suppose I have a STL map where the values are pointers, and I want to delete them all. How would I represent the following code, but making use of std::for_each? I\'m happy for
Have you tried using BOOST_FOREACH ? That should allow you to do that in a line without creating your own functor.
I have not tested the following code but it should look something like this(if not exactly):
typedef stdext::hash_map MyMapType; //see comment.
BOOST_FOREACH( MyMapType::value_type& p, myMap )
{
delete p.second;
}
Well thats more than 1 line, due to the typedef :)