|
From: thant.tessman on 15 Apr 2008 14:43 I'm using an instance of the boost::variant type as the token value of a non-trivial grammar. The type list is 24 items long. Apparently there is a type list limit of 20 items. Is this correct? Is this just a matter of building the cases, or is it dictated by some platform limit on template type arguments? (Is it actually dictated by the apply_visitor template?) Thanks for any info. (I briefly wandered around the boost headers, but their organization is not transparent to the uninitiated.) -thant -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Carl Barron on 15 Apr 2008 19:13 In article <894696dc-a056-4b9c-b90f-38280a72321c(a)m1g2000pre.googlegroups.com>, <thant.tessman(a)gmail.com> wrote: > I'm using an instance of the boost::variant type as the token value of > a non-trivial grammar. The type list is 24 items long. Apparently > there is a type list limit of 20 items. Is this correct? Is this just > a matter of building the cases, or is it dictated by some platform > limit on template type arguments? (Is it actually dictated by the > apply_visitor template?) > > Thanks for any info. (I briefly wandered around the boost headers, but > their organization is not transparent to the uninitiated.) > > -thant It is defined as BOOST_MPL_LIMIT_LIST_SIZE so if you need more than 20 items, you will need to reconfigure mpl and not use its preprocessed headers which is the default. Perhaps you can split the variant into two variants and have a variant of variants. can four or more be split off. typedef boost::variant< T1,T2,T3,T4,T5,...,T12> varaint_1; typedef boost::variant<T12,T13,....,T24> variant_2; typedef boost::variant<variant_1,variant_2> my_variant; struct my_visitor:public boost::static_visitor<T> { struct visitor_1:boost::static_visitor<T> { T operator () (T1 x); // handle T1 - T12; }; struct visitor_2:boost::static_visitor<T> { // handle T13-T24 }; T operator () (variant_1 const &x) { return boost::apply_visitor(visitor_1(),x); } T operator () (variant_2 const &x) { return boost::apply_visitor(visitor_2(),x); } }; should be able to visit your 24 types. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: courpron on 16 Apr 2008 02:33 On Apr 16, 7:43 am, thant.tess...(a)gmail.com wrote: > I'm using an instance of the boost::variant type as the token value of > a non-trivial grammar. The type list is 24 items long. Apparently > there is a type list limit of 20 items. Is this correct? Yes, the limit is 20 by default. Look at "boost/variant/ variant_fwd.hpp" and search for the macro BOOST_VARIANT_LIMIT_TYPES which defines this limit. See also the macro BOOST_VARIANT_VISITATION_UNROLLING_LIMIT in "boost/variant/detail/ visitation_impl.hpp", which defines the limit specifically for the visitation mechanism (also 20 by default). > Is this just > a matter of building the cases, or is it dictated by some platform > limit on template type arguments? (Is it actually dictated by the > apply_visitor template?) 20 is an arbitrary choice that had to be made for putting a max limit on : - the number of template arguments a variant can handle, since C++ doesn't support variadic templates yet. - the number of cases in the switch-case statement of the apply_visitor function. Note that, no matter the actual number of types given when instantiating a variant, that switch-case will always have the maximal number of cases (20 cases or, more accurately BOOST_VARIANT_VISITATION_UNROLLING_LIMIT cases) , which is a pity since there are techniques to adapt the number of cases depending on the number of template arguments. Alexandre Courpron. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Pages: 1 Prev: copy constructor not being called Next: Differentiating pimpl idiom classes in c++ |