How might I assume a “default value” when parsing using boost::spirit?

拜拜、爱过 提交于 2019-12-05 20:43:07

It looks like you can do this with the boost::qi::attr auxiliary parser.

int default_value = 14;

qi::rule<Iterator, int(),              ascii::space_type> some_optional_rule;
qi::rule<Iterator, std::vector<int>(), ascii::space_type> some_rule;

some_optional_rule %= int_ | attr(default_value);
some_rule          %= repeat(2)[int_] >> repeat(2)[some_optional_rule];

I'm still not sure if this is the best way to do this though.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!