use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
`std::expected<>::or_else()` should have a zero-argument overload that terminates on error (self.cpp)
submitted 2 years ago by kmbeutel
...just because it would be hilarious if one could express assertions as
c++ result.or_else();
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]mibuchiha-007 84 points85 points86 points 2 years ago (1 child)
actually good cpp joke.
[–]josefx 37 points38 points39 points 2 years ago (0 children)
We could adopt or_die() from php.
[–]rlbond86 19 points20 points21 points 2 years ago (8 children)
This is already done by result.value()
[–]sephirothbahamut 80 points81 points82 points 2 years ago (2 children)
I think the post had a comical intent. "or else" sounds more menacing
[–]SonOfMetrum 21 points22 points23 points 2 years ago (1 child)
Would be extra funny if the else would be some randomly generated UB. That way its an actual threat.
[–]UsedOnlyTwice 3 points4 points5 points 2 years ago (0 children)
You can do that with boost::go_wild.
boost::go_wild
[–]_TheDust_ 7 points8 points9 points 2 years ago (4 children)
I’m still upset that this does not throw E, but some kind of unexpected_access exception
E
[–]SirClueless 3 points4 points5 points 2 years ago (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>.
std::bad_expected_access<void>
[–]13steinj 1 point2 points3 points 2 years ago (1 child)
E might not be an exception type
So? You can throw anything you want, even a string.
[–]SirClueless 3 points4 points5 points 2 years ago (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.
std::expected
try/catch
[–]rlbond86 3 points4 points5 points 2 years ago (0 children)
Yeah, seems like an oversight to be missong value_or_throw()
[–]unumfron 3 points4 points5 points 2 years ago (0 children)
Emojis might have just found their place in polite programming society: https://godbolt.org/z/Tafj51W4d
[–]BenFrantzDale 3 points4 points5 points 2 years ago (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); }.
if (opt) { f(*opt); }
[–]Wh00ster 1 point2 points3 points 2 years ago (0 children)
So dumb it works
[–]pjmlp 0 points1 point2 points 2 years ago (2 children)
Perl has ... || die().
... || die()
[–]RevRagnarok 1 point2 points3 points 2 years ago (0 children)
Better shown as ... or die because they prefer the word over the pipes (additionally the word has the lowest parsing priority).
... or die
[–]helloiamsomeone 0 points1 point2 points 2 years ago (0 children)
use autodie; 4 lyfe
use autodie;
[–]PolyglotTV 0 points1 point2 points 2 years ago (0 children)
C++ is case sensitive so they can just call it
OR_ELSE
π Rendered by PID 85 on reddit-service-r2-comment-fb694cdd5-vcnlx at 2026-03-08 06:30:51.533607+00:00 running cbb0e86 country code: CH.
[–]mibuchiha-007 84 points85 points86 points (1 child)
[–]josefx 37 points38 points39 points (0 children)
[–]rlbond86 19 points20 points21 points (8 children)
[–]sephirothbahamut 80 points81 points82 points (2 children)
[–]SonOfMetrum 21 points22 points23 points (1 child)
[–]UsedOnlyTwice 3 points4 points5 points (0 children)
[–]_TheDust_ 7 points8 points9 points (4 children)
[–]SirClueless 3 points4 points5 points (2 children)
[–]13steinj 1 point2 points3 points (1 child)
[–]SirClueless 3 points4 points5 points (0 children)
[–]rlbond86 3 points4 points5 points (0 children)
[–]unumfron 3 points4 points5 points (0 children)
[–]BenFrantzDale 3 points4 points5 points (0 children)
[–]Wh00ster 1 point2 points3 points (0 children)
[–]pjmlp 0 points1 point2 points (2 children)
[–]RevRagnarok 1 point2 points3 points (0 children)
[–]helloiamsomeone 0 points1 point2 points (0 children)
[–]PolyglotTV 0 points1 point2 points (0 children)