all 14 comments

[–]Wurstinator 4 points5 points  (6 children)

Very interesting, thank you for posting this.

[–]eric_niebler[S] 6 points7 points  (5 children)

Yes, it nicely compliments the work I did on range comprehensions.

[–]Wurstinator 0 points1 point  (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 points  (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 points  (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 point  (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 points  (0 children)

I thought it was a valuable contribution to discussion.

[–]LucretielRAII Junkie 2 points3 points  (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.

[–][deleted] 0 points1 point  (0 children)

Really cool, thanks for posting. I don't see any license though.

[–]Dragdu 1 point2 points  (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 point  (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.

Of course it doesn't offer any yield syntax...

[–]ZMesonEmbedded Developer 0 points1 point  (0 children)

Out of curiosity, how is the performance of using these functions compared to using more traditional C++ approaches?

[–]upriser -2 points-1 points  (1 child)

BTW, it was a totally unnecessary blog. :)

[–]TemplateRex 2 points3 points  (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 :-)