As the C++ language has evolved over the years, new features and functionality have been added to make programming more efficient and expressive.
What is std::optional
?
In C++17, std::optional
and the <optional>
header were added, allowing programmers to cleanly handle optional values without needing to use some type of programmer-defined special value.
One clear use case for std::optional
is for a return value that may fail. Consider the following example:
#include <iostream>…