8.boost_array_any
2024-08-30 02:56:11
#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();
}
最新文章
- PHP5各个版本的新功能和新特性总结
- mvc导出excel 之 新
- poj 1556 The Doors
- hdu 4185 二分图匹配
- PHP 设计模式 笔记与总结(2)开发 PSR-0 的基础框架
- java线程实践记录
- Retrofit所有知识场景汇总
- 几个.net的GUI控件库
- C++学习笔记--Season 2
- C51汇编伪指令
- The example program of C on point
- nodejs抓取数据一(列表抓取)
- Oracle知识梳理(三)操作篇:SQL基础操作汇总
- 可编辑的div ->; 编辑框
- 52.tableViewCell重用机制避免重复显示问题
- Java之List排序功能举例
- 将BAT文件注册为服务的方法
- 安装deb包解决依赖问题
- turntable
- xpath教程二 ---- 通过ID和Class检索