🗞️ It is useful for situations where you want to indicate the absence of a value in a clearer and safer way than using null pointers.
std::optional is a functionality introduced in the C++17 standard library that encapsulates an optional value, that is, a value that can or cannot be present.
It is useful for situations where you want to indicate the absence of a value in a clearer and safer way than using null pointers or special values.
Let’s see some examples of use!
01. Creation and basic use
02. Using std::optional with std::string
03. Handling std::optional
04. Working with functions that return std::optional
In summary, std::optional is an elegant and safe way to handle optional values in C++, providing a clearer and less error-prone alternative compared to using null pointers or special values.