c++ - C++11 range-based for loops without loop variable -


in c++ need iterate number of times, don't need iteration variable. example:

for( int x=0; x<10; ++x ) {     /* code goes here, not reference "x" in code */ } 

i realize can replacing "code goes here" lambda or named function, question loops.

i hoping c++11's range-based loops help:

for( auto x : boost::irange(0,10) ) {     /* code goes here, not reference "x" in code */ } 

but above gives "unreferenced local variable" since never explicitly reference x.

i'm wondering if there more elegant way write above loops code not generate "unreferenced local variable" warning.

there may way very doubt more elegant. have in first loop correct way it, limiting scope/lifetime of loop variable.

i ignore unused variable warning (it's indication compiler may wrong, after all) or use compiler facilities (if available) turn off warning @ point.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -