如何将BOOST_PP_CAT两次应用于较短的C ++重复代码?

问题描述

我需要编写很多这样的代码(实际上是flex规则文件):

true { return yy::parser::make_T_TRUE(yy::parser::token::T_TRUE,yy::location()); }
false { return yy::parser::make_T_FALSE(yy::parser::token::T_FALSE,yy::location()); }
try { return yy::parser::make_T_TRY(yy::parser::token::T_TRY,yy::location()); }
catch { return yy::parser::make_T_CATCH(yy::parser::token::T_CATCH,yy::location()); }
finally { return yy::parser::make_T_FINALLY(yy::parser::token::T_FINALLY,yy::location()); }

如果我有这样的宏,则可以看到:

#define MAKE(t) return yy::parser::make_ ## t (yy::parser::token:: ## t,yy::location())

然后我可以编写更少的重复代码,生活会更轻松:

true { MAKE(T_TRUE); }
false { MAKE(T_FALSE); }
try { MAKE(T_TRY); }
catch { MAKE(T_CATCH); }
finally { MAKE(T_FINALLY); }

但是##BOOST_PP_CAT不能在一行中被两次调用,第二个扩展将无法工作。

有什么办法解决这个问题吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)