#include <iostream>
#include <string>
#include <boost/array.hpp>
//异构的容器
#include <boost/any.hpp>
#include <vector>
#include <typeinfo>
#include <algorithm>
using namespace std;
using namespace boost; void main()
{
boost::array<string, >mystr = { "","ab","","ef","" };
boost::array<string, >::iterator ib = mystr.begin();
boost::array<string, >::iterator ie = mystr.end();
for (; ib != ie; ib++)
{
cout << *ib << endl;
} //返回数组首地址
string *p = mystr.data();
cout << *p << endl;
mystr[] = "";
mystr.at() = ""; //异构容器
std::vector<boost::any> s_values;
s_values.push_back();
s_values.push_back('A');
s_values.push_back(19.8);
s_values.push_back("");
//cout << boost::any_cast<double>(s_values[2]) << endl; for_each(s_values.begin(),s_values.end(),
[](const boost::any &anydata)
{
//获取类型
const std::type_info &ti = anydata.type();
//根据类型执行相应的操作
if (ti == typeid(int))
{
cout << boost::any_cast<int>(anydata) << endl;
}
else if (ti == typeid(double))
{
cout << boost::any_cast<double>(anydata) << endl;
}
else if (ti == typeid(const char *))
{
cout << boost::any_cast<const char *>(anydata) << endl;
}
else if (ti == typeid(char))
{
cout << boost::any_cast<char>(anydata) << endl;
}
}); cin.get();
}

8.boost_array_any的更多相关文章

随机推荐

  1. linux下配置虚拟域名

    linux下配置虚拟域名 1.hosts文件位置! /etc/hosts 2.增加一行 127.0.0.1 xxxxx 3.修改apache中的vhosts vi /etc/httpd/extra/h ...

  2. xbox 相关

    https://live.xbox.com/zh-CN/avatareditor xboxgames://

  3. Electron 问题

    打包 Mac 桌面程序时报上述错误 E:\research\node\XXX>electron-packager ./ XXX --platform=darwin --arch=x64 --ic ...

  4. spring mvc 项目 相关配置文件小结

    web.xml文件主要配置如下: 需要加载的配置文件: 类路径下,可以使用通配符配置  类似:classpath:conf/spring/*/*.xml, <context-param> ...

  5. learn cmake

    cmake简介 在cmake出现之前,在linuxiax下,大型软件系统一般使用make来控制编译过程,而在Windows下可能是用vs下一个project来构建.一个复杂的系统本身依赖关系就很麻烦, ...

  6. Unity 声音播放不受Time.scale为0的影响

    其他会暂停,目前发现声音不受影响 嗯,就这样.

  7. criteria的projection做分页

  8. 命令行导入导出Mysql数据库

    MySQL命令行导出数据库:1,进入MySQL目录下的bin文件夹:cd MySQL中到bin文件夹的目录,如我输入的命令行:cd C:\Program Files\MySQL\MySQL Serve ...

  9. ubuntu 12.04下安装Qt出现cannot execute binary file的解决方案

    最近在ubuntu 12.04下安装QT的过程中,遇到一个问题. ./qt-opensource-linux-x64-5.7.0.run出现了bash: ./qt-opensource-linux-x ...

  10. debian 9 安装Virtual Box

    1.去官网下载deb包,例如包名: virtualbox-.2_5.2.18-124319_Debian_stretch_amd64.deb 2.安装 .2_5.2.18-124319_Debian_ ...