logoalt Hacker News

unclad5968last Tuesday at 6:22 PM2 repliesview on HN

I'm certainly open to discussion, but your comment doesn't really have any substance to respond to.


Replies

aystaticlast Tuesday at 6:28 PM

You've managed to miss the entire point of using a union: the value is either a success payload or an error value, never both.

You can't encode that mutual exclusivity if you return a std::pair or std::tuple. That's exactly why std::expected, std::variant, or Rust enums exist, to make that constraint explicit in the type system.

show 1 reply
masklinnlast Tuesday at 7:14 PM

> I'm certainly open to discussion

That is certainly not how your comment comes across.