Possible Duplicate:
C++11 reverse range-based for-loop
Is there an inverse range-based for
in C++11
?
I want to do something like this:
for(int value : vec)
{
cout << value << endl;
}
To do this:
for(auto it = vec.rbegin(); it != vec.rend(); ++it)
{
cout << *it << endl;
}
For instance:
for(int value : -vec)
{
cout << value << endl;
}
Is possible do something like that to do an inverse loop?
You can just use Boost.Range's reversed adaptor:
for(int value : ( vec | boost::adaptors::reversed ))
{...}
But standard C++11 doesn't have a similar feature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With