[wallet] Don't hold cs_LastBlockFile while calling setBestChain
[bitcoinplatinum.git] / src / reverse_iterator.h
blob409f895ce062f0db78a991de833522e227d51e1c
1 // Taken from https://gist.github.com/arvidsson/7231973
3 #ifndef BITCOIN_REVERSE_ITERATOR_HPP
4 #define BITCOIN_REVERSE_ITERATOR_HPP
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 &x;
19 public:
20 reverse_range(T &x) : x(x) {}
22 auto begin() const -> decltype(this->x.rbegin())
24 return x.rbegin();
27 auto end() const -> decltype(this->x.rend())
29 return 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_HPP