Search⌘ K
AI Features

std::optional

Explore the use of std optional in C++17 to manage optional values safely and clearly. Understand how std optional helps avoid error-prone special values, manage in-place construction, and handle missing data with exceptions or default values. This lesson teaches you to write clearer and more robust code using std optional for scenarios like database queries or uncertain return values.

We'll cover the following...

std::optional is quite comfortable for calculations such as database queries that may have a result.

🔑 Don’t use no-results
Before C++17 it was common practice to use a special value such as a null pointer, an empty string, or a unique integer to denote the absence of a result. These special values or no-results are ...