Hi,
It seems that the lambda manual lacks of a simple working example.
I'm made up the following example. But it's not working. Could you
please show me how to make it work?
Thanks,
Peng
#include
Hi Yu, I happen to have finished reading lambda docs just a while ago... :-) std::cout << (_1 + _2)(boost::lambda::make_const(10), boost::lambda::make_const(10)); std::cout << std::endl; does the job. You have to be careful about passing constants as arguments, see docs for details. As for std::endl, the problem is that the resulting value (result of std::cout << _lambda_expression_) has some special type. There are some workarounds, try googling on that if this worries you. Cheers, Filip
Hi,
It seems that the lambda manual lacks of a simple working example.
I'm made up the following example. But it's not working. Could you please show me how to make it work?
Thanks, Peng
#include
#include #include <iostream> using namespace boost::lambda;
int main() { std::cout << (_1 + _2)(10, 10) << std::endl; } _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Filip Konvic(ka LOGIS, s.r.o. tel. +420 556 841 100 mob. +420 736 758 714
On 3/14/07, Filip Konvic(ka
Hi Yu,
I happen to have finished reading lambda docs just a while ago... :-)
std::cout << (_1 + _2)(boost::lambda::make_const(10), boost::lambda::make_const(10)); std::cout << std::endl;
does the job. You have to be careful about passing constants as arguments, see docs for details. As for std::endl, the problem is that the resulting value (result of std::cout << _lambda_expression_) has some special type. There are some workarounds, try googling on that if this worries you.
Cheers, Filip
Hi, Thank you for your pointer. I don't have enough time to read through all the manual. Can you point to me which particular section I should read for this problem? Thanks, Peng
On 3/14/07, Filip Konvic(ka
wrote: Hi Yu,
I happen to have finished reading lambda docs just a while ago... :-)
std::cout << (_1 + _2)(boost::lambda::make_const(10), boost::lambda::make_const(10)); std::cout << std::endl;
does the job. You have to be careful about passing constants as arguments, see docs for details. As for std::endl, the problem is that the resulting value (result of std::cout << _lambda_expression_) has some special type. There are some workarounds, try googling on that if this worries you.
Cheers, Filip
Hi,
Thank you for your pointer. I don't have enough time to read through all the manual. Can you point to me which particular section I should read for this problem?
Thanks, Peng
Sure: http://www.boost.org/doc/html/lambda/le_in_details.html#lambda.rvalues_as_ac... http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?Suggestions_-... Cheers, Filip
"Peng Yu"
I'm made up the following example. But it's not working. Could you please show me how to make it work?
#include
#include #include <iostream> using namespace boost::lambda;
int main() { std::cout << (_1 + _2)(10, 10) << std::endl; }
The function object -- the result of _1 + _2 -- requires T&, and therefore you can't pass constants to it. The following will work: int n1 = 10; int n2 = 10; cout << (_1 + _2)(n1, n2) << endl; HTH, Arkadiy
participants (4)
-
Arkadiy Vertleyb
-
Filip Konvic(ka
-
Filip Konvička
-
Peng Yu