calling member function with boost lambda

Started by
2 comments, last by Darklighter 15 years, 10 months ago
ive got a list with several objects... id like to call a member function for each of these objects with boost lambda... instead of for (...) list[n].Foo(); id like for_each(list.begin(), list.end(), ???); how would i do that?
Advertisement
You don't need boost.lambda for that, the standard library provides:
for_each(list.begin(), list.end(), std::mem_fun_ref(&Type::Foo) );
Quote:Original post by rip-off
You don't need boost.lambda for that, the standard library provides:
*** Source Snippet Removed ***


yea i guess i could do it like that...

and what if i for example use a map instead and want to call pair->second->Foo()?
Quote:Original post by Dragon_Strike
and what if i for example use a map instead and want to call pair->second->Foo()?

#include <boost/bind.hpp>std::for_each(m.begin(), m.end(), boost::bind(&Type::Foo, boost::bind<Type&>(&std::map<int, Type>::value_type::second, _1)));

This topic is closed to new replies.

Advertisement