Jump to content
  • Advertisement
Sign in to follow this  
Dragon_Strike

calling member function with boost lambda

This topic is 3741 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
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) );

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!