如何在Boost Fusion向量中识别类型

4
如何识别 boost::fusion 向量中的类型?
例如:
fusion::vector<int, double, string> v;

我希望有一种方法可以识别v[0]为类型intv[1]为类型doublev[2]为类型string

谢谢。


我记得没有 v[0] 这样的东西,因为你需要一个编译时的结构。你尝试了什么?你想要做什么? - Matthieu M.
2个回答

6
为了从 boost::fusion::vector 中提取一个元素,你需要使用 boost::fusion::at_c,像这样:
boost::fusion::vector<int, std::string> v(1, "hello");
std::cout << boost::fusion::at_c<0>(v) << std::endl; // prints 1

位置N处的类型是:
boost::fusion::result_of::at_c<boost::fusion::vector<int, std::string>, 1>::type

0

这个链接 描述了我试图做的事情。

具体来说,以下是我尝试实现的内容:

template<int N, typename T>
struct a_struct{
typedef typename T::value_type etype;
typedef typename boost::fusion::result_of::value_at<etype, boost::mpl::int_<N> >::type a_type;
};

其中,T 是一个由 boost::fusion 向量组成的 std::vector。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接