Boost Variant resembles union. You can store values of different types in a boost::variant.

1.

#include <boost/variant.hpp>
#include <string> int main() {
boost::variant<double, char, std::string> v;
v = 3.14;
v = 'A';
v = "Boost";
}

boost::variant is a template, at least one parameter must be specified. One or more template parameters specify the supported types.

2. accessing values in boost::variant with boost::get()

#include <boost/variant.hpp>
#include <string>
#include <iostream> int main() {
boost::variant<double, char, std::string> v;
v = 3.14;
std::cout << boost::get<double>(v) << std::endl;
v = 'A';
std::cout << boost::get<char>(v) << std::endl;
v = "Boost";
std::cout << boost::get<std::string>(v) << std::endl;
return ;
}

to display the stored values of v, use the free-standing function boost::get().

最新文章

  1. (分享)多功能 PDF转换器v3.0版本
  2. JVM 运行时数据区域
  3. 插入并列div使其居中
  4. UVa 11107 (后缀数组 二分) Life Forms
  5. 使用split进行分割时遇到特殊字符的问题
  6. 简单说pyglet.event
  7. network: Android 网络推断(wifi、3G与其它)
  8. Python学习笔记——基础篇【第五周】——模块
  9. 用node搭建简单的静态资源管理器
  10. 解决Failed to load the JNI shared library xxx/xxx/jvm.dll 错误
  11. JQuery下拉控件select的操作汇总
  12. 设置div中的div居中显示
  13. 有趣的API: history pushState/popstate 无刷新跳转(pjax)
  14. poj2993
  15. Android APK反编译就这么简单 具体解释
  16. SQL---MySQL数据库---试炼
  17. 使用redis实现简单的锁机制
  18. 反射-Class
  19. spring计时工具类stopwatch用法
  20. 【2017.12.18】Dijkstra专题

热门文章

  1. Linux 用户和组信息
  2. 利用 Skywalking 搭建 APM(应用性能管理)— 安装与配置
  3. Windows 下开启FTP服务并创建FTP用户
  4. day33—前端开发的模块化和组件化
  5. openstack——glance镜像服务
  6. MySQL 基准测试
  7. get_date.sh
  8. JS原型链详解
  9. [暑假集训Day1T1]黑暗城堡
  10. [CodeForces 52C]Circular RMQ