4

我正在使用该库boost::variant来存储大量类型。随着类型的数量越来越多,我很快就会达到 20 种的限制。在文档中,似乎可以使用 a 定义变体mpl::vector,它允许超过 20 种类型(如果我是正确的,最多 50 种)。我试图像这样替换我的变体定义:

#include <boost/variant.hpp>
#include <boost/mpl/vector.hpp>

typedef boost::mpl::vector<
    float,
    math::float2,
    math::float3,
    relative_point<1>,
    relative_point<2>,
    relative_point<3>,
    std::string,
    color,
    group,
    dictionnary,
    reference,
    line,
    strip,
    text,
    font
> variant_mpl_vec;

typedef boost::make_variant_over<variant_mpl_vec>::type data_type;

// This is the old definition
/*typedef boost::variant<
    float,
    math::float2,
    math::float3,
    relative_point<1>,
    relative_point<2>,
    relative_point<3>,
    std::string,
    color,
    group,
    dictionnary,
    reference,
    line,
    strip,
    text,
    font
> data_type;*/

我直接把我的代码。大多数类型是包含很少数据的结构。

编译时,我得到一个奇怪的:

error: no matching function for call to ‘boost::detail::variant::make_initializer_node::apply<boost::mpl::pair< ... and lots more ...

以前的变体定义工作正常,所以我很惊讶我的替换不起作用。我是新手,mpl所以也许我错过了一些东西 - 但找不到什么!我过得好吗?

提前致谢。

4

1 回答 1

1

Variant type definition is correct, the problem was due to a generic function in the program taking an arbitrary variant as parameter. Indeed, make_variant_over<mpl::vector<T0, T1, ...>> behaves like variant<T0, T1, ...> but is not the same type: it is a variant<over_sequence<vector<T0, T1, ...>>> (so T0 corresponds to over_sequence<vector<T0, T1, ...>>.

于 2011-07-23T18:30:35.293 回答