r/cpp • • Sep 16 '17

Useful GCC warning options not enabled by -Wall -Wextra

https://kristerw.blogspot.com/2017/09/useful-gcc-warning-options-not-enabled.html
164 Upvotes

71 comments sorted by

View all comments

Show parent comments

3

u/dodheim Sep 18 '17 edited May 22 '18
for (auto idx = container.size(); idx--;)

Short and to the point; don't overthink the simple stuff. ;-]

1

u/donalmacc Game Developer Sep 18 '17

Easy solution, but what about accessing the items in the container? You're now back to the temporary variable solution above.

2

u/dodheim Sep 18 '17 edited Sep 18 '17

It's an index variable in a for loop just like any other – why would this pose an issue for accessing items in the container? If the intent was to iterate a collection in reverse, that's exactly what this accomplishes.

EDIT: I just noticed I used the wrong decrement in my comment. :-S Fixed now, if that relates to your point. Demo here: http://coliru.stacked-crooked.com/a/513850b14acd68a4

1

u/donalmacc Game Developer Sep 18 '17

Oh. Now I totally understand! Makes much more sense now!