3 ms·
exactly, use std::expected as the return type, avoid exceptions, and make a failable factory constructor to build your type. Make invalid states unrepresentable
by noitpmeder 6mo 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!!!
- dietr1ch 6mo agoAren't you time-travelling? std::expected is C++23 (so available starting from 2025-2027 xd) https://en.cppreference.com/cpp/utility/expected https://en.cppreference.com/cpp/utility/expected
- diath 6mo agoIt 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 https://godbolt.org/z/on1v6qdf3 These days compiler developers implement accepted standard features pretty fast.
- noitpmeder 6mo agoAnd tl::expected (a largely identical impl) has been available similarly as long!