Boost中的boost::optional
来源:互联网 发布:淘宝店铺公告模板 编辑:程序博客网 时间:2024/06/05 12:48
<span style="background-color: rgb(255, 255, 255);"></span>
#include <iostream>#include "boost/optional.hpp"#include <cassert>namespace bo = boost;int main(){// constructor bo::optional<int> a;bo::optional<int> b(bo::none);assert(a == b);assert(!a.is_initialized());assert(!b.is_initialized());bo::optional<int> c(3);assert(c == 3);assert(c.is_initialized());bo::optional<int> d(true, 4);assert(d == 4);assert(d.is_initialized());bo::optional<int> e(false, 4);assert(e == bo::none);assert(!e.is_initialized());bo::optional<int> f = 1;assert(f.is_initialized());// member functiona = 2;if (a){std::cout << "a is is_initialized" << std::endl;}a.reset();assert(!a);// std::cout << a.get() << std::endl;// ERROR!程序崩溃// std::cout << "a.value(): " << a.value() << std::endl;// 程序异常a = 300; // 确保在使用get和value前a已经被初始化std::cout << "a.get(): " << a.get() << std::endl;// OKstd::cout << "operator * : " << *a << std::endl;// try ... catchstd::cout << "a.value(): " << a.value() << std::endl;// operator->()std::cin.get();}
0 0
- Boost中的boost::optional
- boost optional
- boost optional
- boost optional
- boost optional
- boost optional
- boost::optional<T>
- boost::optional详解
- boost optional<T>
- C++学习 boost::optional详解
- boost 库实用工具之optional
- Boost.Optional 的定义与使用
- boost 笔记点滴:optional 和 variant
- BOOST中的union:boost::variant
- Boost中的容器boost::any
- Boost中的容器boost::tuple
- Boost
- boost
- Python day01周
- linux CentOS 6忘记密码的解决办法
- SQL查询关键字位置并截取;查询重复;
- 工具之wireshark检测不到网卡的问题
- 1015. 德才论 (25)
- Boost中的boost::optional
- Gallery控件笔记
- linux yum install
- JDK与设计模式:工厂模式
- 四六级考试
- 用tableView自动布局注意事项
- 【C语言】实现Linux下的cp命令的基本功能
- topic model
- linux 查看日志命令