Skip to main content Skip to navigation

C++ 2011 reverse Iterators


template <typename T>struct reverse_range{private:T& x_;
public:
reverse_range (T& x): x_ (x) {}
auto begin () const -> decltype (this->x_.rbegin ())
{
return x_.rbegin ();
}
auto end () const -> decltype (this->x_.rend ())
{
return x_.rend ();
}
};
template <typename T>
reverse_range<T> reverse_iterate (T& x)
{
return reverse_range<T> (x);
}
std::vector<int> v = {1, 2, 3, 5, 7, 11};
for (auto x: reverse_iterate (v))
...;