3 ms·
Not the same, Optional is like Option in Rust, it’s about existence, not success or failure. I believe std::expected is the correct answer but it’s unclear to
by steveklabnik 6y ago
Not the same, Optional is like Option in Rust, it’s about existence, not success or failure.
I believe std::expected is the correct answer but it’s unclear to me if it actually made it into the standard yet or not. I thought it had but can only find proposals...
- zabzonk 6y agoAFAIK its not yet into any standards, possibly because the semantics are really complex (don't know how rust specifies them) - useful discussion here: https://www.reddit.com/r/cpp/comments/c75ipk/why_stdexpected_is_not_in_the_standard_yet_is_it/ https://www.reddit.com/r/cpp/comments/c75ipk/why_stdexpected...
- shaklee3 6y agoIsn't Optional used in a lot of cases where empty means failure?
- marcosdumay 6y agoThat's not enough. Hacking failure reporting into an existence API will make your code confusing, and will leave you no way to report multiple types of errors.
- steveklabnik 6y agoIt might be, but that doesn’t make it semantically the correct thing. As always, it depends. But traditionally, most languages that use this strategy have both, and they aren’t interchangeable. I can see this happening more when you only have optional, though.