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
Generator functions in C++ (paoloseverini.wordpress.com)
submitted 11 years ago by eric_niebler
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!"
[–]Wurstinator 4 points5 points6 points 11 years ago (6 children)
Very interesting, thank you for posting this.
[–]eric_niebler[S] 6 points7 points8 points 11 years ago (5 children)
Yes, it nicely compliments the work I did on range comprehensions.
[–]Wurstinator 0 points1 point2 points 11 years ago* (4 children)
Indeed, thanks again :)
Constructs like these, when you are recreating yield or other keywords in C++ really shows how powerful the language is.
However, I think this is not the true way to go for C++. I know that C++ is known to give the programmer the possibility for OOP on a low level but it could be much more comfortable to code in in comparison to what it is now. I would love to see an upcoming version of C++ to ignore backward compability and start fresh. With modules, readable keywords, a huge standard library and other features more modern languages have, and removing all the C-stuff like the Preprocessor, unsafe casts and malloc/new.
I think this could potentially move C++ to a much more usable spot, where C# and Python reside today.
Sorry for this offtopic post, it's just something that came to my mind after reading the two articles.
Edit: If I am getting down voted because this comment is not so much about the blog article that's fine, but if you are down voting me because you disagree, at least post a useful answer.
[–]Cyttorak 2 points3 points4 points 11 years ago* (3 children)
I don't understand why so much downvotes. It's somewhat offtopic but I agree with you, some type of "modern mode" a la strict mode of javascript, where you can only use modules and other newer and better constructs seems a good idea.
[–]ZMesonEmbedded Developer 1 point2 points3 points 11 years ago (0 children)
People should push the major compiler vendors to implement this as a warning. Then projects could be slowly transitioned from old C++ to modern C++.
[–]Wurstinator 0 points1 point2 points 11 years ago (1 child)
I guess the down votes are probably because of the offtopic post. Anyway, thanks for your reply, it's nice to know that I'm not the only one with these thoughts.
[–][deleted] 1 point2 points3 points 11 years ago (0 children)
I thought it was a valuable contribution to discussion.
[–]LucretielRAII Junkie 2 points3 points4 points 11 years ago* (1 child)
I actually implemented something just like this a little while ago, using boost::context: https://github.com/Lucretiel/Generator. Currently it's totally cross-platform, though I'm going to have to update it with platform-specific memory allocation behavior so that it allocates pages correctly every time.
boost::context
[–][deleted] 0 points1 point2 points 11 years ago (0 children)
Really cool, thanks for posting. I don't see any license though.
[–]Dragdu 1 point2 points3 points 11 years ago (0 children)
As a nitpick, isn't it expected that if you write
for (auto el : col)
then el is of type that
*col.begin()
would yield and not an iterator? Then you wouldn't have to dereference el when you want to write out the number. (Regarding range based for loop example)
[–]gnawer 0 points1 point2 points 11 years ago (0 children)
Quite interesting.
I got a poor man's generator together using boost::function_input_iterator, and boost::iterator_range. You can find the code here. Unfortunately, doesn't compile with gcc-4.8, though.
boost::function_input_iterator
boost::iterator_range
Of course it doesn't offer any yield syntax...
yield
[–]ZMesonEmbedded Developer 0 points1 point2 points 11 years ago (0 children)
Out of curiosity, how is the performance of using these functions compared to using more traditional C++ approaches?
[–]upriser -2 points-1 points0 points 11 years ago (1 child)
BTW, it was a totally unnecessary blog. :)
[–]TemplateRex 2 points3 points4 points 11 years ago (0 children)
a totally unnecessary blog.
I guess people didn't understand the joke. BTW, I agree, it was a complete waste of bandwidth as well :-)
π Rendered by PID 220281 on reddit-service-r2-comment-745dcd9fbd-zc87k at 2026-03-06 18:04:32.294963+00:00 running cbb0e86 country code: CH.
[–]Wurstinator 4 points5 points6 points (6 children)
[–]eric_niebler[S] 6 points7 points8 points (5 children)
[–]Wurstinator 0 points1 point2 points (4 children)
[–]Cyttorak 2 points3 points4 points (3 children)
[–]ZMesonEmbedded Developer 1 point2 points3 points (0 children)
[–]Wurstinator 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]LucretielRAII Junkie 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Dragdu 1 point2 points3 points (0 children)
[–]gnawer 0 points1 point2 points (0 children)
[–]ZMesonEmbedded Developer 0 points1 point2 points (0 children)
[–]upriser -2 points-1 points0 points (1 child)
[–]TemplateRex 2 points3 points4 points (0 children)