Remove unused variables and/or function calls
[bitcoinplatinum.git] / src / reverse_iterator.h
blobab467f07c98dedb02d5859b6ac55a8c68894eee1
1 // Taken from https://gist.github.com/arvidsson/7231973
3 #ifndef BITCOIN_REVERSE_ITERATOR_H
4 #define BITCOIN_REVERSE_ITERATOR_H
6 /**
7 * Template used for reverse iteration in C++11 range-based for loops.
8 *
9 * std::vector<int> v = {1, 2, 3, 4, 5};
10 * for (auto x : reverse_iterate(v))
11 * std::cout << x << " ";
14 template <typename T>
15 class reverse_range
17 T &m_x;
19 public:
20 explicit reverse_range(T &x) : m_x(x) {}
22 auto begin() const -> decltype(this->m_x.rbegin())
24 return m_x.rbegin();
27 auto end() const -> decltype(this->m_x.rend())
29 return m_x.rend();
33 template <typename T>
34 reverse_range<T> reverse_iterate(T &x)
36 return reverse_range<T>(x);
39 #endif // BITCOIN_REVERSE_ITERATOR_H