加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 使用mpl :: vector定义boost :: variant类型

发布时间:2020-12-16 06:57:00 所属栏目:百科 来源:网络整理
导读:我正在使用库boost :: variant来存储大量类型.随着类型数量的增加,我很快就会达到20种类型的限制.在文档中,似乎可以使用mpl :: vector定义变体,它允许超过20种类型(如果我是正确的话,最多50种).我试图像这样替换我的变体定义: #include boost/variant.hpp#i
我正在使用库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,font
> data_type;*/

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

编译时,我有一个奇怪的:

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

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

提前致谢.

解决方法

变体类型定义是正确的,问题是由于程序中的泛型函数采用任意变量作为参数.实际上,make_variant_over< mpl :: vector< T0,T1,...>>表现得像变体< T0,...>但不是同一类型:它是变体< over_sequence< vector< T0,...>>> (因此T0对应于over_sequence< vector< T0,...>.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读