【发布时间】:2011-07-21 09:29:44
【问题描述】:
我正在使用库boost::variant 来存储大量类型。随着类型的数量越来越多,我很快就会达到 20 种的限制。在文档中,似乎可以使用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 的新手,所以也许我错过了一些东西 - 但找不到什么!我过得好吗?
提前致谢。
【问题讨论】:
-
高级问题。由于变体的定义,这似乎不是问题,而是将变体作为输入
boost::variant<T0>的通用函数。此函数将T0视为boost::detail::variant::over_sequence<boost::mpl::vector< ... types ...> >,暂时不明白为什么。
标签: c++ boost-mpl boost-variant