Boost logo

Boost Users :

Subject: Re: [Boost-users] doubt on lambda expression
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2009-11-11 09:04:53


On Wed, Nov 11, 2009 at 5:20 AM, Roman Perepelitsa
<roman.perepelitsa_at_[hidden]> wrote:
> 2009/11/11 Emanuele Rocci <rocciemanuele_at_[hidden]>
>>
>> Hi All
>> I started playing with boost::lambda and I need some help or some
>> clarification about it
>> or some hint to better understanding how does it work.
>> I have this piece of code
>> using namespace boost::lambda;
>> using boost::lambda::var;
>> int main(int argc, char** argv) {
>>    std::vector< int > myList;
>>    myList.push_back(100);
>>    myList.push_back(200);
>>    int interval = 20;
>>    std::for_each( myList.begin(), myList.end(),
>>         (
>>         std::cout << "value: " << _1 << "\n",
>>         std::cout << "interval: " << var( interval ) << "\n",
>>         var( interval )++
>>         ));
>> }
>
> Instead of
>   std::cout << "value: " << _1 << "\n",
> do this
>   std::cout << constant("value: ") << _1 << "\n",
> It's described here:
> http://www.boost.org/doc/libs/1_40_0/doc/html/lambda/using_library.html#lambda.introductory_examples.
> By the way, if you are just starting with lambda, it's better to use
> Boost.Phoenix instead.

This is another +1 for Boost.Phoenix2, it does everything lambda and
bind does, and a great deal more. Boost.Phoenix3 is a proto'fied
Phoenix that is still being made and will be all the more powerful and
much more extendable and combinable with other things as well, so it
would be good to learn Boost.Phoenix2 now.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net