Jump to content
  • Advertisement
Sign in to follow this  
Zbychs

boost::lambda question

This topic is 3146 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

Hi This works:
using namespace boost::lambda;
typedef std::istream_iterator<int> in;
std::for_each( in(std::cin), in(), std::cout << (_1 * 3) << " " );
And now I'm trying to do something like this:
std::for_each( str.begin(), str.end(), std::cout << _totupper(_1) << " " );
It doesn't work. Any ideas how I can fix it?

Share this post


Link to post
Share on other sites
Advertisement
Been a while since I used boost::lambda.

Try replacing _1 with boost::var(_1).

I vaguely recall something like that. Also, note that boost.lambda is going to be deprecated eventually since it's superseded by boost.phoenix, which currently isnt't have an independent library, it is distributed as part of boost.spirit so you can find the documentation there.

Share this post


Link to post
Share on other sites
Thanks cache_hit, but it still doesn't work.

error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'boost::_bi::bind_t<R,F,L>'

Any other ideas?

Share this post


Link to post
Share on other sites
Aha, boost::lambda and boost::bind use incompatible placeholders. Replace _1 with boost::lambda::_1. Generally speaking #include'ing boost/bind.hpp and anything from lambda in the same translation unit can cause problems due to placeholder issues

Share this post


Link to post
Share on other sites
Quote:
Original post by Zbychs
It doesn't work.
Any ideas how I can fix it?


What's _totupper? Is it smart enough to delay the evaluation of that function until inside the 'loop'? In other words, does _totupper(_1) return a functor?

You'll probably have to use boost::lambda::bind:


// assuming _totupper is a function
using boost::lambda::bind;
using boost::lambda::_1;
std::for_each( str.begin(), str.end(), std::cout << bind(&_totupper, _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!