Header Reference: <optional>
Header Reference: <optional>
The main type, operations, and usage patterns around std::optional and optional-style APIs.
Header Reference: <optional>
The main type, operations, and usage patterns around std::optional and optional-style APIs.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
Header reference pages are meant to answer a practical question quickly: what this header provides, when to reach for it, and which usage rules are easiest to get wrong.
<optional>std::optional<T>std::nullopthas_value(), value(), and value_or()std::expectedstd::variant#include <optional>
#include <string>
std::optional<std::string> lookup(bool found) {
if (!found) {
return std::nullopt;
}
return "value";
}