Hi AllI started playing with boost::lambda and I need some help or some clarification about itor 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 )++ ));} I understood that writing a lambda expression would be a substitutefor writing a functor. I expected the following result value: 100interval: 20value: 200interval: 21 Instead I had the following intervalfirst value: 1002020021 Why the strings "interval" and "first" are not written for each value and how can I achieve this?Kind RegardsMn _________________________________________________________________ Più di 30 Web Radio: le trovi su Messenger http://www.messenger.it/radioMessenger.aspx
2009/11/11 Emanuele Rocci
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#lamb... . By the way, if you are just starting with lambda, it's better to use Boost.Phoenix instead. Roman Perepelitsa.
On Wed, Nov 11, 2009 at 5:20 AM, Roman Perepelitsa
2009/11/11 Emanuele Rocci
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#lamb.... 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.
On Wed, Nov 11, 2009 at 8:20 AM, Ryan McConnehey
OvermindDL1 wrote:
Phoenix that is still being made
Since it's not in the standard documentation area it would mean it's in the sandbox or vault?
Phoenix3 (note the *3*) is still being made. Phoenix 1 is in boost now, but it is in the Spirit library, look in it. Phoenix 2 is in Boost 1.39 (maybe earlier, unsure), also in the Spirit library (phoenix2 includes). Phoenix 3 will be completely stand-alone, but is on hold until someone has time to donate to it. So yes, it is in Boost right now and has been for a very long time, but it is in the Spirit library, so look in its docs and search for Phoenix until you find a link to the Phoenix sub-docs.
Phoenix 3 will be completely stand-alone, but is on hold until someone has time to donate to it.
I am actually doing this with the blessing of Joel & harmut ;) -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35
Hi Roman Thanks! It works and thanks for Phoenix advice!Mn
Date: Wed, 11 Nov 2009 13:20:26 +0100
From: roman.perepelitsa@gmail.com
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] doubt on lambda expression
2009/11/11 Emanuele Rocci
participants (5)
-
Emanuele Rocci
-
joel
-
OvermindDL1
-
Roman Perepelitsa
-
Ryan McConnehey