Manage Optional Values with std::optional

Learn to manage optional values with std::optional.

We'll cover the following

Introduced with C++17, the std::optional class holds an optional value.

Consider the case where we have a function that may or may not return a value. For example, a function that checks if a number is prime but returns the first factor if there is one. This function should return either a value or a bool status. We could create a struct that carries both value and status:

Get hands-on with 1400+ tech skills courses.