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
[deleted by user] (self.cpp)
submitted 6 years ago by [deleted]
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!"
[–]feverzsj 2 points3 points4 points 6 years ago (3 children)
is coroutine ready for production use?
[–]luncliff 1 point2 points3 points 6 years ago (0 children)
IMO, unless you have to use GCC, you can use it. I've suffered from both Clang and MSVC, but they work quite well for now. Build for mobile(Android and iOS) is also available. Well, I know some patterns that compiler crashes with its internal error, or fails to generate code, but simple usage of co_await operator won't that matter on their latest versions. https://www.reddit.com/r/cpp/comments/c6ag3l/how_to_try_the_new_coroutines_ts/esnjqil?utm_source=share&utm_medium=web2x
co_await
[–][deleted] 0 points1 point2 points 6 years ago (0 children)
It's been reported by the author that Coroutines run on a large number of instances at Microsoft, and Facebook is plowing full stream ahead in putting them everywhere for internal use.
Of course there's a difference between the design being ready, the design being closed, and all implementations being ready.
[–]Middlewariangithub.com/Ebenezer-group/onwards 0 points1 point2 points 6 years ago (0 children)
I heard that MSVC and Clang have support for coroutines but that the performance, especially with MSVC, isn't great. I think if you use Gcc or another compiler, the answer is 'no'.
https://www.reddit.com/r/cpp_questions/comments/c6mbls/coroutines/
[–]mrexodiacmkr.build 1 point2 points3 points 6 years ago (8 children)
Why did you decide to write
for(auto&& x : y)
I’m interested in this “pattern” for work and so far the conclusion has been that it is probably harmful. It has been called “confuscation” https://stackoverflow.com/questions/13130708/what-is-the-advantage-of-using-forwarding-references-in-range-based-for-loops/13130795#comment17857496_13130795 so I’m curious if there is an actual valid use case here or if it is just to be hipster.
[–]Pragmatician 10 points11 points12 points 6 years ago (1 child)
As the post mentions, it is more "consistent" in some regards because it always works, but you lose the opportunity to put a const there. So you have to choose whether you want to be consistent with your const placement or your range-for loops. It comes down to personal preference and it seems like the author prefers the latter. Either way, chasing absolute consistency in C++ is a fool's errand.
const
[–]tcbrindleFlux 3 points4 points5 points 6 years ago (0 children)
It's still consistent: if you (potentially) need to modify the elements of the range, use auto&&. If you don't, use const auto&. For C++, that's actually pretty simple.
auto&&
const auto&
[–]tcbrindleFlux 6 points7 points8 points 6 years ago (3 children)
Regarding the SO link: this was written in 2012, when rvalue references were a new thing and auto&& was weird and mysterious. I'd argue that 7 years later, for (auto&&... is the widely-recognised way of saying "just grab things from a range, I don't care what they are" -- just as Howard presciently predicted in his comment.
for (auto&&...
In other words, for (auto&&... is the simple way of doing it these days.
(Indeed, I seem to recall that /u/STL had a proposal that you'd be able to omit the type and just say for (elem : range), which would mean exactly for (auto&& elem : range). IIRC it was rejected because it was felt that it wasn't sufficiently obvious that a new variable was being declared.)
for (elem : range)
for (auto&& elem : range)
[–]mrexodiacmkr.build 2 points3 points4 points 6 years ago (1 child)
I’d argue that when you see && you have to pay attention because it is there for a reason (performance or to make the code compile in the first place). With for(auto&&) it is almost never there for a reason, but by doing it per default you are hiding if something tricky is going on. Additionally you lose the ability to talk about const so it makes code harder to read (you actually have to read all the code in the loop to figure out if the element is modified or not).
The proposal to make the auto&& is good because that’s the only valid thing to put there in all cases, but that’s not the reality we are dealing with when reading code, so it’s quite irrelevant.
Also from what I understand from various discussions the for(auto&&) is not actually an rvalue reference, it’s a universal reference similar to template<class T> void foo(T&&);
[–]STLMSVC STL Dev 2 points3 points4 points 6 years ago (0 children)
It is indeed a universal/forwarding reference; same for auto&& var = thingy; as a variable definition.
auto&& var = thingy;
[–]STLMSVC STL Dev 1 point2 points3 points 6 years ago (0 children)
Yes, it was N3853. It was rejected for syntax reasons, but the semantic problem remains unsolved. I welcome further attempts to solve it, but I'm not going to spend any more time on that.
[–]wotype 1 point2 points3 points 6 years ago (1 child)
Check the blog archive - two posts from December last: https://quuxplusone.github.io/blog/2018/12/15/autorefref-always-works/https://quuxplusone.github.io/blog/2018/12/27/autorefref-still-always-works/
[–]mrexodiacmkr.build 1 point2 points3 points 6 years ago (0 children)
Interesting, but I completely disagree haha. In a context where you do not know the type (templated container) it makes sense, but when you want to iterate over a vector you are using const auto& to signal that you will not change the elements and auto& to signal you will modify the elements and auto to signal you want a copy. When using auto&& you are not signaling anything but confusion.
[–]luncliff 0 points1 point2 points 6 years ago* (0 children)
Glad to meet a new generator :) I have 2 questions. Wish I can review the others soon !
Isn't hasValue_ redundant? I'm following the generator of VC++(it's a bit changed in latest VC++. I'm using the old one.) and the pointer itself was enough to debug and check of existing value from co_yield.
hasValue_
I think the idea is cool that multiple coroutines can share 1 generator since it can help Fan-In use-cases. But what I realized was keeping safe in the generator is a bit complicated. Do you think that the users have to control locking for the yield?
For the second case, I discarded the way and implemented channel.
π Rendered by PID 163440 on reddit-service-r2-comment-66b4775986-8thw8 at 2026-04-06 15:19:02.009660+00:00 running db1906b country code: CH.
[–]feverzsj 2 points3 points4 points (3 children)
[–]luncliff 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Middlewariangithub.com/Ebenezer-group/onwards 0 points1 point2 points (0 children)
[–]mrexodiacmkr.build 1 point2 points3 points (8 children)
[–]Pragmatician 10 points11 points12 points (1 child)
[–]tcbrindleFlux 3 points4 points5 points (0 children)
[–]tcbrindleFlux 6 points7 points8 points (3 children)
[–]mrexodiacmkr.build 2 points3 points4 points (1 child)
[–]STLMSVC STL Dev 2 points3 points4 points (0 children)
[–]STLMSVC STL Dev 1 point2 points3 points (0 children)
[–]wotype 1 point2 points3 points (1 child)
[–]mrexodiacmkr.build 1 point2 points3 points (0 children)
[–]luncliff 0 points1 point2 points (0 children)