Hacker News new | ask | show | jobs
by noitpmeder 51 days ago
exactly, use std::expected as the return type, avoid exceptions, and make a failable factory constructor to build your type. Make invalid states unrepresentable!!!
1 comments

Aren't you time-travelling? std::expected is C++23 (so available starting from 2025-2027 xd)

https://en.cppreference.com/cpp/utility/expected

It has been available since GCC 12.1 (May 2022), Clang 19.1 (Sep 2024), and Visual Studio 17.13 (2022~): https://godbolt.org/z/on1v6qdf3

These days compiler developers implement accepted standard features pretty fast.

And tl::expected (a largely identical impl) has been available similarly as long!