boost :: phoenix defines statement blocks using the "," operator (see forcing phoenix block statements ). I am trying to use this construct in the semantic part of the boost :: spirit rule. However, it seems that only the last statement in the statement block is executed. The following is a minimal compiled example that shows the problem:
#include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/include/phoenix_fusion.hpp> #include <boost/spirit/include/phoenix_stl.hpp> #include <boost/spirit/include/phoenix_object.hpp> #include <boost/spirit/include/phoenix_operator.hpp> int main() { using boost::spirit::qi::int_; using boost::phoenix::ref; using boost::spirit::qi::phrase_parse; using boost::spirit::ascii::space; int a = 0; int b = 0; const std::string s("1"); bool f = phrase_parse(s.begin(),s.end(), int_[ ref(a)=1, ref(b)=2 ], space); std::cout << f << ": a=" << a << ", b=" << b << std::endl; }
This program (using boost 1.52) prints
1: a = 0, b = 2
but I was expecting a = 1, b = 2. So should this work? Why?
Thanks!
source share