Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • I don't think auto keyword was present before c++11 so I would not say it is very classical c++. If I may ask a question here in the comment, would "auto const" tell the compiler that it can rearrange all elements as it wants? Maybe it will be easier for the compiler to plan to avoid branching if that is the case. Commented Jul 17, 2016 at 9:50
  • 1
    @mathreadler The sooner people stop worrying about "classical c++", the better. C++11 was a macroevolutionary event for the language & is 5 years old: it should be the minimum we strive for. Anyway, the OP tagged that and C++14 (even better!). No, auto const has no bearing whatsoever on iteration order. If you look up ranged-based for, you'll see that it basically does a standard loop from begin() to end() with implicit dereferencing. There's no way it could break the ordering guarantees (if any) of the container being iterated over; it would've been laughed off the face of the Earth Commented Jul 17, 2016 at 19:34
  • 1
    @mathreadler, actually it was, it just had quite a different meaning. What was not present is range-for... and any other distinct C++11 feature. What I meant here was that range-fors, std::futures, std::functions, even those anonymous closures are very well C++ish in the syntax; every language has its own parlance and when incorporatin new features it tries to make them mimic the old well-known syntax. Commented Jul 17, 2016 at 21:36
  • @underscore_d, a compiler is allowed to perform any transformations provided the as-if rule is obeyed, isn't it? Commented Jul 17, 2016 at 21:39
  • 1
    Hmmm, and what can possibly be meant by that? Commented Jul 20, 2016 at 18:30