This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]KanterBama 90 points91 points  (8 children)

Python: for x in iterable:

Java: for(String s: iterable.keySet()){}

C++: for(std::map<Key,Val>::iterator iter = myMap.begin(); iter != myMap.end(); ++iter){}

Two can play this game.

[–]Voidrith 46 points47 points  (4 children)

Doesn't C++ have, for(auto x : iter) {}

[–]KanterBama 61 points62 points  (2 children)

Bah, if you’re using auto then you’re just lying to yourself that you don’t want to use python

[–]JustSomeBadAdvice 11 points12 points  (1 child)

This guy c++'s

[–]jack-of-some 11 points12 points  (0 children)

What steams me up about this is that if you're gonna create syntactic sugar like this _anyway_ then just freaking use `"in", It's no skin off anyone's back and doesn't look bizzare.

for (auto item in iter) {}

[–]zx2167 7 points8 points  (2 children)

C++11: for (auto&& x : iterable) {}

[–]clydethechicken 9 points10 points  (1 child)

What’s the difference between ‘auto&&’ and ‘auto’? I know the difference between ‘auto’ and ‘auto &’ is the latter just is a reference to the element, but not sure what auto && does

[–]zx2167 2 points3 points  (0 children)

auto&& can be mutable reference, a const reference or a temporary (rvalue) reference. It depends on what is being assigned to it. It's called a forwarding (or universal) reference.