# boost::lambda question

## 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 on other sites
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 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 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 on other sites
Quote:
 Original post by ZbychsIt 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 functionusing boost::lambda::bind;using boost::lambda::_1;std::for_each( str.begin(), str.end(), std::cout << bind(&_totupper, _1) << " " );

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628275
• Total Posts
2981759

• 10
• 11
• 17
• 10
• 9