3 ms·
> How do you deal with (for example) a constructor that fails? The usual alternative is to have a factory function that returns std::optional<T> or std::expect
by leni536 2y ago
> How do you deal with (for example) a constructor that fails?
The usual alternative is to have a factory function that returns std::optional<T> or std::expected<T, Err>. This avoids two-stage init, but has other tradeoffs.
- ghosty141 2y agoWorks rather well in rust but in c++ its not as nice for one because of the lack of something like rusts question mark operator. (Tbf thats kinda workaroundable with compiler extensions but MSVC for example doesn‘t have most of them)