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