I'm trying to get my program working without boost
usage, but can't find an alternative of some useful patterns. Namely, I can't find boost::optional
-likewise pattern in the standard library. Is there some standard alternative for boost::optional
(C++11 or somewhere else)?
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.
std::optional
is part of C++17. –
Asinine There is currently a proposal for C++14 (or C++17). So the answer is (probably) not yet :).
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).
© 2022 - 2024 — McMap. All rights reserved.
boost::optional
. Or maybestd::unique_ptr
, where the value 0 (null_ptr, NULL) is interpreted an uninitialized optional type. Besides the drawbacks the good thing is that you dont need to implement anything; but just keep the abstraction in mind. A clue about this is given in the boost manual itself boost.org/doc/libs/1_53_0/libs/optional/doc/html/boost_optional/… "As a result, you might be able to replace optional<T> by T* on some situations but not always" – Shirlyshiroma