On Sun, 04 Jul 2004 20:41:05 +0100, Dylan wrote:
> At the moment I often find myself doing something like the following
>
> std::list<MyClass*> mcl;
>
> /.../fill mcl with some elements
>
> //now call aMethod() for each element;
> for (std::list<MyClass*>::iterator it = mcl.begin();
> it != mcl.end();
> ++it)
> {
> it->aMethod();
> }
>
> Is there a *convenient* way of using something like std::for_each to
> achieve the same result as the loop shown in the previous code
> snippet?
I think you could use something like:
std::for_each(mcl.begin(), mcl.end(), std::mem_fun(&MyClass::aMethod))
If you want it to be even more powerful, try Boost. For instance, look at
this sample:
http://www.boost.org/libs/bind/bind....ith_algorithms
Regards,
Josep