boost-数据类型之auto、any、tuple、variant
2016-09-21 14:03
330 查看
1、auto
auto是C++11中的关键字,它可以定义任意类型元素,eg:
View Code
4、variant
variant是一种增强的union,C/C++中union只能持有POD(普通数据类型),而不能持有如string、vector等复杂类型,boost的variant则没有这个限制。
auto是C++11中的关键字,它可以定义任意类型元素,eg:
#include <cstdio> #include <string> using std::string; #include "boost/tuple/tuple.hpp" boost::tuple<int, double, string> func() { int i = 1; double d = 5.0; string s("hello"); boost::tuple<int, double, string> tupleCombin(i, d, s); return tupleCombin; } int main() { boost::tuple<int, double, string> tupleCombin = func(); int i = tupleCombin.get<0>(); double d = tupleCombin.get<1>(); string s = boost::get<2>(tupleCombin); return getchar(); }
View Code
4、variant
variant是一种增强的union,C/C++中union只能持有POD(普通数据类型),而不能持有如string、vector等复杂类型,boost的variant则没有这个限制。
相关文章推荐
- boost::any( 能存放任何类型的数据)原理
- boost中自动确定数据类型(BOOST_TYPEOF和BOOST_AUTO)的使用
- boost在自己主动确定数据类型(BOOST_TYPEOF和BOOST_AUTO)使用
- 白乔原创:万能类型boost::any
- VARIANT数据类型
- 数据类型转换(三) _variant_t to CString
- VBScript 数据类型-Variant
- 让Boost.python支持Boost::any类型。
- 4.6.1 万能类型boost::any
- 我要从com向应用程序返回一个结构,结构中包括二进制数据,请问用什么方式传替比较好呢?BSTR,VARIANT还是其他什么类型比较好呢
- COM的数据类型BSTR,Variant
- SQL Server所支持的 Sql_variant 数据类型
- 万能数据类型any杂谈
- SQL Server所支持的 Sql_variant 数据类型
- 不允许从数据类型 sql_variant 到 varbinary 的隐式转换
- _variant_t 数据类型
- 解决错误:sql_variant is incompatible with xml (ASP.NET 2.0 / XML数据类型 )
- VARIANT 数据类型简单介绍
- _variant_t转换数据类型
- ActiveDAQ控件的VC编程 数据采集 VARIANT数据类型的使用