C++ 23 · Classes, memory and templates

Return a value or an error

std::expected holds a result or an error without exceptions (C++23).

std::expected<int, std::string> parse(const std::string& s) {
    try { return std::stoi(s); }
    catch (...) { return std::unexpected("not a number"); }
}

Official C++ 23 documentation

More classes, memory and templates commands

All classes, memory and templates commands · C++ 23 cheatsheet

Was this page helpful?