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';

Official C++ 23 documentation

More containers and algorithms commands

All containers and algorithms commands · C++ 23 cheatsheet

Was this page helpful?