Is it there an inverse range based on C ++ 11?

Possible duplicate:
C ++ 11 for-loop based on inverse range

Is there a reverse range forin C++11?

I want to do something like this:

for(int value : vec)
{
    cout << value << endl;
}

For this:

for(auto it = vec.rbegin(); it != vec.rend(); ++it)
{
    cout << *it << endl;
}

For instance:

for(int value : -vec)
{
    cout << value << endl;
}    

Is it possible to do something similar for a reverse loop?

+5
source share
1 answer

You can just use Boost. Change reverse adapter :

for(int value : ( vec | boost::adaptors::reversed ))
{...}

But standard C ++ 11 does not have a similar function.

+9
source

All Articles