#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. hdoj--1251--统计难题(字典树)

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Subm ...

  2. [IOI 1998] Polygon

    [题目链接] http://poj.org/problem?id=1179 [算法] 区间DP [代码] #include <algorithm> #include <bitset& ...

  3. js 智能识别收获地址

    项目地址https://github.com/wzc570738205/smart_parse 支持以下数据格式 马云,1351111111,北京市朝阳区姚家园3楼 马云1351111111北京市朝阳 ...

  4. 深度理解Jquery 中 scrollTop() 方法

    这是工作遇到scrollTop() 方法.为了强化自己,把它记录在博客园当中. 下面就开始scrollTop 用法讲解: scrollTop() 定义和用法 scrollTop() 方法设置或返回被选 ...

  5. JavaScript学习笔记——对象的创建

    对象是JavaScript基本数据类型,在JavaScript中除了Undefined.Null.布尔型(ture.false).字符串和数字之外,其他的都属于对象. 在JavaScript中,一个对 ...

  6. vue.js和node.js的认识

    首先vue.js 是库,不是框架,不是框架,不是框架. Vue.js 使用了基于 HTML 的模版语法,允许开发者声明式地将 DOM 绑定至底层 Vue 实例的数据. Vue.js 的核心是一个允许你 ...

  7. 41.使用SAX读取XML

    main.cpp #include <QtGui> #include <iostream> #include "saxhandler.h" int main ...

  8. POJ 1201 差分约束+SPFA

    思路: 差分约束,难在建图.(我是不会告诉你我刚学会SPFA的...) 把每个区间的ai–>bi连一条长度为ci的边. k–>k+1连一条长度为0的边. k+1–>k连一条长度为-1 ...

  9. 关于优化for循环的注意的事项

    for循环注意事项: 1.for循环内部尽量少做数据库查询之类的IO代价大的操作 2.尽量控制for循环的次数,不多做无用功 3.能一次加载在内存中的,就不要通过循环来多次查询数据库,除非数据量过大. ...

  10. SyntaxError Generator expression must be parenthesized

    环境: Windows10 python3.7.0 Django1.11.15 异常 启动Django时抛出以下异常: Unhandled exception in thread started by ...