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

c – Casting boost :: fusion :: vector

发布时间:2020-12-16 07:34:15 所属栏目:百科 来源:网络整理
导读:boost :: fusion :: vector的编号形式看起来像 template class T1class vector1; templateclass T1,class T2class vector2; 等等 可变形式看起来像 templateclass T1 = boost::fusion::void_,class T2 = boost::fusion::void_class vector; 那么有没有办法在
boost :: fusion :: vector的编号形式看起来像

template <class T1>
class vector1; 

template<class T1,class T2>
class vector2;

等等

可变形式看起来像

template<class T1 = boost::fusion::void_,class T2 = boost::fusion::void_>
class vector;

那么有没有办法在编译时将boost :: fusion :: vector从编号转换为可变形式?

解决方法

你真的需要编译时演员吗?两者之间存在运行时转换,所以我无法真正看到需求:

vector2<int,char> a(13,'b');
vector<int,char> b = a;

然而我试着玩.我对我的回答并不满意,但也许你可以努力找到更好的东西.

我希望能够使用一些元函数,但它似乎超出了我的能力.此外,使用此方法,您需要将其定义为具有不同值的次数.

也许更好的解决方案是首先转换为元组…

#include <boost/fusion/container/vector.hpp>
#include <boost/fusion/container/vector/vector10.hpp>
#include <boost/fusion/include/at.hpp>
#include <boost/type_traits/remove_reference.hpp>
using namespace boost::fusion;

template<typename NumVec2>
struct cast {
    typedef typename result_of::at_c<NumVec2,0>::type T1;
    typedef typename result_of::at_c<NumVec2,1>::type T2;
    typedef vector<typename boost::remove_reference<T1>::type,typename boost::remove_reference<T2>::type > type;
};

int main(int,char**){
    vector2<int,'b');
    typedef cast< vector2<int,char> >::type casted_t;
    casted_t other(10,'f');
}

(编辑:李大同)

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

    推荐文章
      热点阅读