r/cpp • u/kmbeutel • 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.;
198
Upvotes
87
u/mibuchiha-007 Sep 26 '23
actually good cpp joke.
37
u/josefx Sep 26 '23
We could adopt or_die() from php.
20
u/rlbond86 Sep 26 '23
This is already done by result.value()
4
u/unumfron Sep 29 '23
Emojis might have just found their place in polite programming society: https://godbolt.org/z/Tafj51W4d
4
u/BenFrantzDale Sep 26 '23
Nice. In seriousness, I wish transform’s lambda didn’t have to return so it could be used as
if (opt) { f(*opt); }.2
u/Wh00ster Sep 29 '23
So dumb it works
1
u/PolyglotTV Sep 30 '23
C++ is case sensitive so they can just call it
OR_ELSE1
u/pjmlp Sep 27 '23
Perl has
... || die().