c++ - How to reverse iterate vector with iterator? -
for example:
for(int i=0;i<v.size();i++){ }
is normal order,
for(int i=v.size()-1;i>=0;i--){ }
is reversed order,
how reverse version of iterator?
for(vector<int>::iterator it=v.begin();it!=v.end();++it){ }
also there reverse version of code style?
for(int : v){ }
use reverse iterator:
for(auto = v.rbegin(); != v.rend(); ++it){/*...*/}
there no built in way range based for
in reverse, use boost::adaptors::reversed
:
for(auto& : boost::adaptors::reversde(v)){/*...*/}
Comments
Post a Comment