MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/70hf7f/useful_gcc_warning_options_not_enabled_by_wall/dn6q4pb
r/cpp • u/mttd • Sep 16 '17
71 comments sorted by
View all comments
Show parent comments
3
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!
1
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!
2
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!
Oh. Now I totally understand! Makes much more sense now!
3
u/dodheim Sep 18 '17 edited May 22 '18
Short and to the point; don't overthink the simple stuff. ;-]