Returning A Value In Any Case One of the most highly regarded and expertly designed C++ library projects in the world - H.Sutter and A.Alexandrescu, C++ Coding Standards
05 March 2015
boost::optional: unleash the power of C++ with Boost libraries.
Boost.Optional class is very close the boost::variant class but for only one type.
boost::optional holds an array of char, where the object of type T can be an in-place constuctor.
It has also a boolean flag to remember the state of the object (if is constructed or not).
To use this class, just add #include <boost/optional.hpp> to your program. See the example below:
Boost.Optional class does not use dinamic allocation, and it does not require a default constructor
for the underlying type.