我正在设计一个verilog语言的解析器,其中一个规则有25个组件,我需要一个大的boost :: variant来保存它:如何增加boost :: variant可以处理的类型的数量
typedef boost::variant<
shared_ptr<T_module_item__port_declaration>
, shared_ptr<T_module_item__generate_region>
, shared_ptr<T_module_item__specify_block>
, shared_ptr<T_module_item__parameter_declaration>
, shared_ptr<T_module_item__specparam_declaration>
, shared_ptr<T_module_item__net_declaration>
, shared_ptr<T_module_item__reg_declaration>
, shared_ptr<T_module_item__integer_declaration>
, shared_ptr<T_module_item__real_declaration>
, shared_ptr<T_module_item__time_declaration>
, shared_ptr<T_module_item__realtime_declaration>
, shared_ptr<T_module_item__event_declaration>
, shared_ptr<T_module_item__genvar_declaration>
, shared_ptr<T_module_item__task_declaration>
, shared_ptr<T_module_item__function_declaration>
, shared_ptr<T_module_item__local_parameter_declaration>
, shared_ptr<T_module_item__parameter_override>
, shared_ptr<T_module_item__continuous_assign>
, shared_ptr<T_module_item__gate_instantiation>
, shared_ptr<T_module_item__udp_instantiation>
, shared_ptr<T_module_item__module_instantiation>
, shared_ptr<T_module_item__initial_construct>
, shared_ptr<T_module_item__always_construct>
, shared_ptr<T_module_item__loop_generate_construct>
, shared_ptr<T_module_item__conditional_generate_construct>
> module_item ;
但g ++抱怨boost :: variant只能容纳不超过20种类型。
verilogast.h|1129 col 2| error: wrong number of template arguments (25, should be 20)
|| > module_item ;
|| ^
/usr/include/boost/variant/variant_fwd.hpp|213 col 53| error: provided for ‘template<class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11, class T12, class T13, class T14, class T15, class T16, class T17, class T18, class T19> class boost::variant’
|| template <BOOST_VARIANT_AUX_DECLARE_PARAMS> class variant;
我试图重新定义BOOST_VARIANT_LIMIT_TYPES较大值:
#define BOOST_VARIANT_LIMIT_TYPES 30
#include<boost/variant.hpp>
但错误仍然存在,
我在搜索答案时已经阅读过这篇文章,但是我发现它来自mpl,而不是变体。但无论如何,它的工作原理非常感谢。 – shengyushen
但编译显着减慢,有什么建议? – shengyushen
我对此没有经验,但我认为[这个问题](http://stackoverflow.com/q/19493630/2417774)可能会有所帮助。不幸的是我直到今晚才能测试它(从现在开始超过12小时)。另一个可能的建议是尝试简化变体,例如,如果它们在模型中有意义,则使用嵌套的'declaration','instantiation'和'construct'变体。 – llonesmiz