Branch data Line data Source code
# 1 : : // Taken from https://gist.github.com/arvidsson/7231973 # 2 : : # 3 : : #ifndef BITCOIN_REVERSE_ITERATOR_H # 4 : : #define BITCOIN_REVERSE_ITERATOR_H # 5 : : # 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 << " "; # 12 : : */ # 13 : : # 14 : : template <typename T> # 15 : : class reverse_range # 16 : : { # 17 : : T &m_x; # 18 : : # 19 : : public: # 20 : 1312128 : explicit reverse_range(T &x) : m_x(x) {} # 21 : : # 22 : : auto begin() const -> decltype(this->m_x.rbegin()) # 23 : 1312128 : { # 24 : 1312128 : return m_x.rbegin(); # 25 : 1312128 : } # 26 : : # 27 : : auto end() const -> decltype(this->m_x.rend()) # 28 : 1312128 : { # 29 : 1312128 : return m_x.rend(); # 30 : 1312128 : } # 31 : : }; # 32 : : # 33 : : template <typename T> # 34 : : reverse_range<T> reverse_iterate(T &x) # 35 : 1312128 : { # 36 : 1312128 : return reverse_range<T>(x); # 37 : 1312128 : } # 38 : : # 39 : : #endif // BITCOIN_REVERSE_ITERATOR_H