Sign in to follow this  

calling member function with boost lambda

This topic is 3460 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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()?

Share this post


Link to post
Share on other sites
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)));

Share this post


Link to post
Share on other sites

This topic is 3460 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this