Я разрабатываю парсер для языка verilog, и одно из правил содержит 25 компонентов, для которых мне нужен большой вариант boost :: для его удержания:Как увеличить количество типов, которые могут обрабатываться 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 часов). Другое возможное предложение может заключаться в том, чтобы попытаться упростить вариант, например, используя варианты вложенного 'объявления',' instantiation' и 'construct', если они имеют смысл в вашей модели. – llonesmiz