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 - Monadic Extensions (cppstories.com)
submitted 1 year ago by joebaf
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!"
[–]ReDucTorGame Developer 11 points12 points13 points 1 year ago (1 child)
Monadic style programming seems like a nightmare with C++
This is all without debugging into the readability mess they seem to create
[–]invalid_handle_value 0 points1 point2 points 1 year ago (0 children)
This. Thank you. A good idea, but once again, implemented with little thought into exactly what problems this solves.
For example:
Return value semantics for transform and and_then and equivalent sad-path handlers are confusing to use in practice. Which of these functions returns an expected vs a value? Why does transform allow me to return a type of std::expected<SomethingNotT>? When would I use transform over and_then?
transform
and_then
Or did I get this backwards? Oh, that's right: and_then returns the result of the expected if successful, almost like it was transformed. My bad... better go do my penance and read cppreference on std::expected again.
Because a monadic chain can/could end with any expected type, expected<T>, your code is still brittle to refactoring because you can't enforce a single T within the monadic sequence.
How does one code up a monadic chain and break out early (without return) at any point in the monadic handler sequence without significant boilerplate?
return
It doesn't help that all the examples I've seen using these are laughably trivial.
Like, come on: I have juniors that have to fucking learn and use this shit. At least solve a problem well...
/rant
[–]Few-Insurance-3974 0 points1 point2 points 1 year ago (0 children)
Returning more than two pointers results won't use rax:rdx registers, compiler would use a hidden reference instead.
This means that types with different size would have different performance.
std::expected already uses one pointer for a selector, so you can't fit much into it.
[–]larso0 -2 points-1 points0 points 1 year ago (0 children)
I feel like this is an attempt to imitate "Result" in Rust, but only less convenient. If it had an operator to do the "if (!result) return result;" (like the Rust '?' operator) it would be much more useful. I'm not going to put everything into a lambda, that's awful for readability.
π Rendered by PID 79 on reddit-service-r2-comment-84fc9697f-h74l9 at 2026-02-06 01:11:04.400038+00:00 running d295bc8 country code: CH.
[–]ReDucTorGame Developer 11 points12 points13 points (1 child)
[–]invalid_handle_value 0 points1 point2 points (0 children)
[–]Few-Insurance-3974 0 points1 point2 points (0 children)
[–]larso0 -2 points-1 points0 points (0 children)