boost::optional alternative in C++ Standard Library

隐身守侯 提交于 2019-11-30 11:07:41

Short answer: No.

Long answer: Roll your own according to the boost spec. The documentation is quite exhaustive and the code isn't that complex, but this still requires above average C++ skills.

To update this answer: C++14 unfortunately did not ship with std::optional. The current proposal (Revision 5) is N3793 and it is expected to be shipped as a separate technical specification or to become part of C++17.

Nova

There is currently a proposal for C++14 (or C++17). So the answer is (probably) not yet :).

Jan Rüegg

Like pmr explained, it is not possible right now, and will not be until C++17 is out.

However, you should be able to use this single header library on github as a drop in replacement of boost- or std optional. It has no dependencies (except a c++11/c++14 capable compiler).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!