C++ 23 · Containers and algorithms
Represent a missing value
std::optional holds a value or nothing, instead of a sentinel like -1.
std::optional<int> find_id(std::string_view name);
if (auto id = find_id("Ada")) std::cout << *id << '\n';
C++ 23 · Containers and algorithms
std::optional holds a value or nothing, instead of a sentinel like -1.
std::optional<int> find_id(std::string_view name);
if (auto id = find_id("Ada")) std::cout << *id << '\n';
Was this page helpful?