Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> 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.



Works 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)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: