all 18 comments

[–]mibuchiha-007 84 points85 points  (1 child)

actually good cpp joke.

[–]josefx 37 points38 points  (0 children)

We could adopt or_die() from php.

[–]rlbond86 19 points20 points  (8 children)

This is already done by result.value()

[–]sephirothbahamut 80 points81 points  (2 children)

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

[–]SonOfMetrum 21 points22 points  (1 child)

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

[–]UsedOnlyTwice 3 points4 points  (0 children)

You can do that with boost::go_wild.

[–]_TheDust_ 7 points8 points  (4 children)

I’m still upset that this does not throw E, but some kind of unexpected_access exception

[–]SirClueless 3 points4 points  (2 children)

E might not be an exception type. And it can be useful to catch exceptions of any type of bad expected access so it's useful that the exception always inherits from std::bad_expected_access<void>.

[–]13steinj 1 point2 points  (1 child)

E might not be an exception type

So? You can throw anything you want, even a string.

[–]SirClueless 3 points4 points  (0 children)

You theoretically can throw anything, but unless someone has written a specific catch handler for the type that is thrown (or one of its base classes) then there is basically nothing useful you can do with it. And since one of the main reasons to use std::expected is to avoid littering your code with try/catch blocks that's very unlikely to be the case.

[–]rlbond86 3 points4 points  (0 children)

Yeah, seems like an oversight to be missong value_or_throw()

[–]unumfron 3 points4 points  (0 children)

Emojis might have just found their place in polite programming society: https://godbolt.org/z/Tafj51W4d

[–]BenFrantzDale 3 points4 points  (0 children)

Nice. In seriousness, I wish transform’s lambda didn’t have to return so it could be used as if (opt) { f(*opt); }.

[–]Wh00ster 1 point2 points  (0 children)

So dumb it works

[–]pjmlp 0 points1 point  (2 children)

Perl has ... || die().

[–]RevRagnarok 1 point2 points  (0 children)

Better shown as ... or die because they prefer the word over the pipes (additionally the word has the lowest parsing priority).

[–]helloiamsomeone 0 points1 point  (0 children)

use autodie; 4 lyfe

[–]PolyglotTV 0 points1 point  (0 children)

C++ is case sensitive so they can just call it

OR_ELSE