boost::phoenix 使用运算符 "," 定义语句块(参见boost phoenix 块语句)。我正在尝试在 boost::spirit 规则的语义操作部分中使用此构造。但是,看起来只执行了语句块中的最后一条语句。这是一个显示问题的最小可编译示例:
#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;
}
该程序(使用 boost 1.52)打印
1:a=0,b=2
但我期待a = 1,b = 2。这是它应该如何工作的吗?为什么?
谢谢!