Boost any库的笔记
来源:互联网 发布:中国银河证券软件 编辑:程序博客网 时间:2024/06/04 23:30
Author: kagula
Date: 2016-03-10
Environment:
[1]Boost 1.57
[2]Visual Studio 2013 Update 5
Prologue:
boost any是万能数据类型,使用它仅包含头文件就可以了,不需要库文件链接。
Content:
// TestBoostAny.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <boost/any.hpp>#include <map>#include <string>#include <iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){map<string, boost::any> mapAny;//测试数据放进去string strValue = "std::string";mapAny["string"] = "string";mapAny["std:string"] = strValue;mapAny["std:string2"] = string("std:string2");mapAny["int"] = 123;mapAny["long"] = 234l;mapAny["float"] = .345f;mapAny["double"] = .456;//测试数据取出来//如果cast了不正确的数据类型会throw exception!map<string, boost::any>::iterator iter = mapAny.begin();while (iter != mapAny.end()){cout << iter->first << ">>>";if (iter->second.type() == typeid(int)){cout << " == typeid(int) " << boost::any_cast<int>(iter->second);}else if (iter->second.type() == typeid(string)){cout << " == typeid(string) " << boost::any_cast<string>(iter->second);}else if (iter->second.type() == typeid(const char*)){cout << " == typeid(const char*) " << boost::any_cast<const char *>(iter->second);}else{cout << "unknown ";}cout << endl;iter++;}cin.get();return 0;}
0 0
- Boost any库的笔记
- boost::any库的使用
- boost::any的介绍
- boost::any的介绍
- Boost学习笔记之any
- boost::any的一般用法
- boost::any 与 boost::variant 的区别
- boost::any 与 boost::variant 的区别
- Boost库之tuple、any和variant的使用
- boost any类库的使用和内部实现细节
- 绪章 Boost 学习笔记之一 any
- boost::any
- Boost::any
- BOOST--any
- boost::any
- boost::any
- Boost::Any
- boost::any
- iOS面试题
- leetcode leetcode 209 : Minimum Size Subarray Sum | Java最短代码实现
- 分布式服务框架dubbo原理解析
- Spring集成ehcache
- FileWriter write 写文件缺失问题
- Boost any库的笔记
- oracle 小项目实战总结
- Java第二次作业
- CakePHP 3.2插件引入插件篇
- Android基础之Sqlite数据库
- HDUACM2031
- 使用Weka进行数据挖掘(Weka教程六)Weka采样Filter/Resample/SMOTE
- 搜索当前用户所有的表
- 关于javascript的this的几道题