Comment

Comment by aystatic

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.

parent aystatic 1 year ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton