[qi][lambda] Get wrong reaction of the qi::rule if I use lambda for the action
Hello,
if I execute the following example, I get the following output "The bad
one The good one a" but I only expected "The good one a".
Why does it happens? Boost 1.47.0 was used.
#include
On Monday, August 15, 2011 01:11:04 PM boost_mailinglist@gmx.de wrote:
Hello,
if I execute the following example, I get the following output "The bad one The good one a" but I only expected "The good one a".
Why does it happens? Boost 1.47.0 was used.
Reformatting code to explain the effect ...
#include
#include #include #include <iostream>
int main() { using boost::spirit::qi::char_; using boost::spirit::qi::parse;
char const *first = "{a}", *last = first + std::strlen(first);
parse( first , last , '{' >> char_("a") [std::cout << "The good one " << boost::lambda::_1 << '\n'] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This will be evaluated eagerly and print "The good one " at rule construction time and return std::cout again .... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... to be picked up the operator overloads of the lambda library to create a lazy function object (aka lambda)
| char_("b") [std::cout << "The bad one " << boost::lambda::_1 << '\n']
Same here.
>> '}' );
return 0; }
P.S.: Use phoenix for maximum satisfaction. Same rules apply.
Am 24.08.2011 10:52, schrieb Thomas Heller:
On Monday, August 15, 2011 01:11:04 PM boost_mailinglist@gmx.de wrote:
Hello,
if I execute the following example, I get the following output "The bad one The good one a" but I only expected "The good one a".
Why does it happens? Boost 1.47.0 was used.
Reformatting code to explain the effect ...
#include
#include #include #include<iostream>
int main() { using boost::spirit::qi::char_; using boost::spirit::qi::parse;
char const *first = "{a}", *last = first + std::strlen(first);
parse( first , last , '{'>> char_("a") [std::cout<< "The good one "<< boost::lambda::_1<< '\n'] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This will be evaluated eagerly and print "The good one " at rule construction time and return std::cout again .... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... to be picked up the operator overloads of the lambda library to create a lazy function object (aka lambda)
| char_("b") [std::cout<< "The bad one "<< boost::lambda::_1<< '\n']
Same here.
>> '}' );
return 0; }
P.S.: Use phoenix for maximum satisfaction. Same rules apply. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Thank you for the clear explanation.
participants (2)
-
boost_mailinglist@gmx.de
-
Thomas Heller