|
View:
New views
8 Messages
—
Rating Filter:
Alert me
|
|
|
doubt on lambda expressionI 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 )++ )); } I understood that writing a lambda expression would be a substitute for writing a functor. I expected the following result value: 100 interval: 20 value: 200 interval: 21 Instead I had the following intervalfirst value: 100 20 200 21 Why the strings "interval" and "first" are not written for each value and how can I achieve this? Kind Regards Mn Screensaver, sfondi e scene: scarica i gadget di Messenger _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: doubt on lambda expression2009/11/11 Emanuele Rocci <rocciemanuele@...>
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. Roman Perepelitsa. _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: doubt on lambda expressionOn Wed, Nov 11, 2009 at 5:20 AM, Roman Perepelitsa
<roman.perepelitsa@...> wrote: > 2009/11/11 Emanuele Rocci <rocciemanuele@...> >> >> 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 mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: doubt on lambda expressionOvermindDL1 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? Ryan _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: doubt on lambda expressionOn Wed, Nov 11, 2009 at 8:20 AM, Ryan McConnehey <mccorywork@...> wrote:
> 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. _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: doubt on lambda expressionIt works and thanks for Phoenix advice! Mn Date: Wed, 11 Nov 2009 13:20:26 +0100 From: roman.perepelitsa@... To: boost-users@... Subject: Re: [Boost-users] doubt on lambda expression 2009/11/11 Emanuele Rocci <rocciemanuele@...>
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. Roman Perepelitsa. Personalizza il tuo spazio online: ritagliati il tuo Spaces _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: doubt on lambda expression> 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 _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
|
|
Re: doubt on lambda expressionOn Wed, Nov 11, 2009 at 9:09 AM, joel <joel.falcou@...> wrote:
> >> 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 ;) Ah, well I certainly eagerly await it! :) _______________________________________________ Boost-users mailing list Boost-users@... http://lists.boost.org/mailman/listinfo.cgi/boost-users |
| Free embeddable forum powered by Nabble | Forum Help |