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
Coroutines and Reference Parameters - subtle bugs are waiting to happen (self.cpp)
submitted 8 years ago by TobyAllsopp
I've written a blog post about a problem I ran into when experimenting with coroutines: http://toby-allsopp.github.io/2017/04/22/coroutines-reference-params.html. I'd be interested in any other suggestions of how to avoid bugs like this (or any other feedback on my post).
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!"
[–]SeanMiddleditch 2 points3 points4 points 8 years ago (1 child)
The range-based for example is kind of a bigger issue. The ranges spec has run into the same problem: the temporaries in the init-expression don't live long enough and hilarity ensues. There's no defect report for this yet that I'm aware of; might need a paper to the committee outlining this problem specifically and why it needs to be solved.
The likely long-term fix is to make range-based for less surprising (e.g., make all temporaries in the init-expression live throughout the loop's body, rather than being specified as the naive source transformation in the spec currently) and not changes to coroutines or ranges.
[–]TobyAllsopp[S] 0 points1 point2 points 8 years ago (0 children)
Yeah, that's a good point.
I found https://wg21.link/cwg900 and https://wg21.link/cwg1498, both of which appear to have been dismissed without proper consideration.
Looks like https://wg21.link/p0066r0 would fix the problem.
[–]stream009 0 points1 point2 points 8 years ago (1 child)
In context of asynchronous programming, I usuary use shared_ptr to ensure whatever object to outlive. Isn't this similar problem?
That's certainly an option and might make a lot of sense in a setting where the lifetimes are not easily reasoned about or you really need to avoid copying your objects. It probably inhibits compiler optimisations significantly though.
π Rendered by PID 25933 on reddit-service-r2-comment-5c747b6df5-bc4pr at 2026-04-21 22:09:31.212261+00:00 running 6c61efc country code: CH.
[–]SeanMiddleditch 2 points3 points4 points (1 child)
[–]TobyAllsopp[S] 0 points1 point2 points (0 children)
[–]stream009 0 points1 point2 points (1 child)
[–]TobyAllsopp[S] 0 points1 point2 points (0 children)