簡體   English   中英

如何將Boost Spirit與超過20種類型的變體一起使用?

[英]How to use Boost Spirit with variant with more than 20 types?

我正在使用Boost Spirit解析一個非常復雜的語法,並且遇到一個具有20多種類型(此處為21種)的變體的問題:

namespace eddic { namespace ast {

typedef boost::mpl::vector<
            Integer,
            IntegerSuffix,
            Float,
            Litteral,
            VariableValue,
            DereferenceValue,
            Expression,
            Unary,
            Null,
            True,
            False,
            ArrayValue,
            FunctionCall,
            MemberFunctionCall,
            Cast,
            BuiltinOperator,
            Assignment,
            SuffixOperation,
            PrefixOperation,
            Ternary
        > types_initial;

typedef boost::mpl::push_back<types_initial, New>::type types;
typedef boost::make_variant_over<types>::type Value;

}}

Boost Spirit無法識別push_back添加的最后一種類型(eddic :: ast :: New)。 當我解析具有此元素的內容時,它將失敗並顯示以下錯誤:

eddic:/usr/include/boost/variant/detail/visitation_impl.hpp:264:類型名Visitor :: result_type boost :: detail :: variant :: visitation_impl(int,int,Visitor&,VoidPtrCV,mpl _ :: false_,NoBackupFlag,其中*,step0 *)[其中哪個= mpl _ :: int_ <0>; step0 = boost :: detail :: variant :: visitation_impl_step,boost :: mpl :: v_item,boost :: mpl :: v_item,boost :: mpl :: v_item,boost :: mpl :: v_item,boost :: mpl: :v_item,boost :: mpl :: v_item,boost :: mpl :: v_item,boost :: mpl :: v_item,boost :: mpl :: v_item,boost :: mpl :: v_item,boost :: mpl :: v_item ,boost :: mpl :: v_item,boost :: mpl :: v_item,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>, 0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0l>,boost :: mpl :: v_iter,boost :: mpl :: v_item,boost :: mpl :: v_item,boost :: mpl :: v_item,boost :: mpl :: v_item,boost :: mpl :: v_item,boost :: mpl :: v_item,boost :: mpl :: v_item,boost :: mpl :: v_item,boost :: mpl :: v_item,boost :: mpl :: v_item,boost :: mpl :: v_item,boost :: mpl :: v_item,boost :: mpl :: v_item,0>,0> ,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0>,0 >,0>,0>,21l>>; 訪客= boost :: variant,boost :: mpl :: vector,eddic :: ast :: Deferred,eddic :: ast :: Deferred,eddic :: ast :: Null,eddic :: ast :: True,eddic :: ast :: False,eddic :: ast :: Deferred,eddic :: ast :: Deferred,eddic :: ast :: Deferred,eddic :: ast :: Deferred,eddic :: ast :: Deferred,eddic :: ast: :Deferred,eddic :: ast :: Deferred,eddic :: ast :: Deferred,eddic :: ast :: Deferred>,0>>,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost: :detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant: :void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void _> :: assigner; VoidPtrCV = const void *; NoBackupFlag = boost :: variant,boost :: mpl :: vector,eddic :: ast :: Deferred,eddic :: ast :: Deferred,eddic :: ast :: Null,eddic :: ast :: True,eddic :: ast :: False,eddic :: ast :: Deferred,eddic :: ast :: Deferred,eddic :: ast :: Deferred,eddic :: ast :: Deferred,eddic :: ast :: Deferred,eddic :: ast: :Deferred,eddic :: ast :: Deferred,eddic :: ast :: Deferred,eddic :: ast :: Deferred>,0>>,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost: :detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant: :void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void_,boost :: detail :: variant :: void _> :: has_fallback_type_; 類型名Visitor :: result_type = void; mpl _ :: false_ = mpl _ :: bool_]:斷言“!” Boost.Variant內部錯誤:“哪個超出范圍。””失敗。

如果我交換兩個元素(例如三元和新),則可以正確識別新元,但不能正確識別三元。 它只是最后一個失敗的元素。

我已經嘗試使用push_front或vector21,但是它並沒有改變任何東西,它始終是有問題的最后一個元素。 我認為這是因為Spirit在將變量復制到我的variant_over類型之前在內部使用了一個變量。

有解決此問題的方法嗎?

我可以將數量減少到20,但是問題是,將來我肯定會更多。

非常感謝您的任何想法

BOOST_MPL_LIMIT_VECTOR_SIZE定義為您想要的任何新限制,但過高通常表示存在設計問題,因此可能值得考慮一下。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM