由于 boost spirit 占位符限制不超过 10 导致编译错误

Compile error due boost spirit placeholder limit not more than 10

我要

"qi::_10 is not a member of qi "

为qi编译语法时出错。

有没有办法增加允许的最大值?

副手:避免大量函数参数的代码味道

也就是说,

之前:

Live On Coliru

#define SPIRIT_ARGUMENTS_LIMIT 10
#include <boost/spirit/include/qi.hpp>

int main() {
    auto& _10 = boost::spirit::labels::_10;
}

之后:

Live On Coliru

#define SPIRIT_ARGUMENTS_LIMIT 11
#include <boost/spirit/include/qi.hpp>

int main() {
    auto& _10 = boost::spirit::labels::_10;
}

奖金

您可以欺骗和硬编码您自己的占位符:

boost::phoenix::actor<boost::spirit::argument<998> > const _999;

注意 998_999 之间的差异;这是一个未记录的实现细节,因此最好不要依赖它,或者至少进行测试。