c++ - 如何识别boost fusion vector 中的类型

标签 c++ boost boost-fusion

如何识别 boost::fusion vector 中的类型?

例如

fusion::vector<int, double, string> v;

然后可以让我将 v[0] 识别为 int 类型,将 v[1] 识别为 double 类型v[2] 作为 string 类型。

谢谢。

最佳答案

为了从 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

关于c++ - 如何识别boost fusion vector 中的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13100982/

相关文章:

c++ - C++ 程序错误

c++ - 创建用于检索字符串 vector 的语法

c++ - boost::uuids::uuid 作为 std::unordered_map 中的键?

swift - 在 Cocoa 应用程序中打开 App Sandbox 时未在套接字上接收任何 UDP 数据

c++ - 如何在异构容器上使用 boost::fusion::transform?

c++ - 如何概括 spirit 解析器以任意顺序获取列表?

javascript - 原生 Javascript 函数如何在 V8 中工作?

c++ - 从 IA-32 中的程序集访问 C++ 中的函数参数

c++ - 返回基于参数类的模板迭代器

c++ - BOOST_FUSION_ADAPT_TPL_STRUCT 和模板数组大小