大佬教程收集整理的这篇文章主要介绍了c – 使用boost :: spirit解析时,如何假设“默认值”?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
some_rule := a b [c [d]]
其中c和d是可选的,如果没有给出,则默认为某个值(假设为14).如果没有给出值,我可以将其默认为14吗?我希望生成的std :: vector总是大小为4.
我最接近的是如下:
qi::rule<Iterator,std::vector<int>(),ascii::space_type> some_rule; some_rule %= int_ >> int_ >> -int_ >> -int_; // ... some_other_rule = some_rule[&some_callBACk_for_int_vectors];
然后,对于未显示的可选值,我将获得0(我相信).然后我将最后的连续0改为14.这不仅错误,而且也不优雅.有一个更好的方法吗?
int default_value = 14; qi::rule<Iterator,int(),ascii::space_type> some_optional_rule; qi::rule<Iterator,ascii::space_type> some_rule; some_optional_rule %= int_ | attr(default_value); some_rule %= repeat(2)[int_] >> repeat(2)[some_optional_rule];
我仍然不确定这是否是最好的方法.
以上是大佬教程为你收集整理的c – 使用boost :: spirit解析时,如何假设“默认值”?全部内容,希望文章能够帮你解决c – 使用boost :: spirit解析时,如何假设“默认值”?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。