[英]Using mpl::vector to define boost::variant types
我正在使用库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
的新手,所以也许我遗漏了一些东西 - 但找不到什么? 我过得好吗?
提前致谢。
变体类型定义是正确的,问题是由于程序中的通用 function 将任意变体作为参数。 实际上, make_variant_over<mpl::vector<T0, T1, ...>>
行为类似于variant<T0, T1, ...>
但不是同一类型:它是一个variant<over_sequence<vector<T0, T1, ...>>>
(所以 T0 对应于over_sequence<vector<T0, T1, ...>>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.