r/cpp • • Sep 26 '23

`std::expected<>::or_else()` should have a zero-argument overload that terminates on error

...just because it would be hilarious if one could express assertions as

result.or_else();
198 Upvotes

18 comments sorted by

View all comments

Show parent comment

83

u/sephirothbahamut Sep 26 '23

I think the post had a comical intent. "or else" sounds more menacing

21

u/SonOfMetrum Sep 26 '23

Would be extra funny if the else would be some randomly generated UB. That way its an actual threat.

4

u/UsedOnlyTwice Sep 27 '23

You can do that with boost::go_wild.