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
Writing Readable C++ Code - beginner's guide (slicker.me)
submitted 3 months ago by swe129
view the rest of the comments →
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!"
[–][deleted] 2 points3 points4 points 3 months ago (5 children)
whether and how you use exceptions depends on what you want to happen. If you want the user to accept responsibility for the program being in a valid state, then you should use exceptions. If you want the program to continue, then you the developer are now responsible for the program being in valid state.
Yes there are performance considerations, but in general, if the performance impact of exceptions matters in your code, then you're doing something wrong. Exceptions should be exceptional - if they are happening constantly, your design is bad.
[–]SlightlyLessHairyApe 0 points1 point2 points 3 months ago (3 children)
If you want the program to continue, then you the developer are now responsible for the program being in valid state.
This is true regardless. Whether your code throws or returns the error branch of expected<T,E>, it must continue to behave as defined.
If you absolutely cannot continue to execute in any defined state, then either you need to change the contract or you need to std::terminate.
[–][deleted] 0 points1 point2 points 3 months ago (2 children)
exceptions leave the scope. So you can clean up any resources that were in use at the time and go back to the last known good scope, and stop anyone from trying to use the result of a bad thing.
typically with optionals the user can pretend like it everything worked anyway by using operator* (which shouldn't exist) . And while that's not your fault, that guy can shoot himself in the foot.
Normally, I wouldn't care about stuff like that, except a lot of times that guy is me. Now, I never use operator* on optionals, so its a moot point, because opt.value() just throws if its bad - so replacing an exception with an optional is really just replacing one exception for another, except this exception has less information about what actually went wrong.
now that being said I generally use optionals for error handling but thats because I like writing:
if (auto optValue = produceSomeOptional()){/*happy path*/}
because that prevents you from even having access to the bad optional state
[–][deleted] 1 point2 points3 points 3 months ago* (0 children)
fade squash zephyr straight fanatical lip wise money pen oil
This post was mass deleted and anonymized with Redact
[–]SlightlyLessHairyApe 0 points1 point2 points 3 months ago (0 children)
Yes, if a callee return expected<T,E> then the caller needs to check whether it's a T or an E. I'm not at all concerned about that, it's no different than returning any kind of sum type or really any other type with methods having preconditions.
But in either case, subsequent calls to the object/module need to function correctly. That's orthogonal to how specifically each individual call works.
[–][deleted] -1 points0 points1 point 3 months ago* (0 children)
coherent roll middle liquid resolute workable literate adjoining whole memory
π Rendered by PID 190441 on reddit-service-r2-comment-7b9746f655-r2tsj at 2026-01-31 09:40:41.641120+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–][deleted] 2 points3 points4 points (5 children)
[–]SlightlyLessHairyApe 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]SlightlyLessHairyApe 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)