logoalt Hacker News

kajika91today at 12:20 AM1 replyview on HN

Not that I like go at all but because of it my C++ is starting to look like it as I am returning tuples of [result, error].

I try to avoid exceptions, is there any better ways? (Variant looks a bit more complicated but could be a totally OK alternative)


Replies

ameliaquiningtoday at 1:01 AM

C++23 introduces std::expected, which is a simpler alternative to std::variant designed specifically for the result-or-error use case. You still don't get pattern matching, but Go-style tuples don't give you that either.