Browse Source
0.15b1268a1
clang-format: Delete ForEachMacros (Jorge Timón)5995735
scripted-diff: Remove #include <boost/foreach.hpp> (Jorge Timón)3eff827
scripted-diff: Remove BOOST_REVERSE_FOREACH (Jorge Timón)33aed5b
Fix const_reverse_iterator constructor (pass const ptr) (Jorge Timón)300851e
Introduce src/reverse_iterator.hpp and include it... (Jorge Timón) Tree-SHA512: df3405328e9602d0a433ac134ba59a5c9a6202ef64188df2f94a59b2ce58dec7c988b25d0671c7937de516a96b2e6daeb9d04c82fa363b616ee4cf6e9cb0fac6
Wladimir J. van der Laan
8 years ago
38 changed files with 53 additions and 39 deletions
@ -0,0 +1,39 @@ |
|||||||
|
// Taken from https://gist.github.com/arvidsson/7231973
|
||||||
|
|
||||||
|
#ifndef BITCOIN_REVERSE_ITERATOR_HPP |
||||||
|
#define BITCOIN_REVERSE_ITERATOR_HPP |
||||||
|
|
||||||
|
/**
|
||||||
|
* Template used for reverse iteration in C++11 range-based for loops. |
||||||
|
* |
||||||
|
* std::vector<int> v = {1, 2, 3, 4, 5}; |
||||||
|
* for (auto x : reverse_iterate(v)) |
||||||
|
* std::cout << x << " "; |
||||||
|
*/ |
||||||
|
|
||||||
|
template <typename T> |
||||||
|
class reverse_range |
||||||
|
{ |
||||||
|
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); |
||||||
|
} |
||||||
|
|
||||||
|
#endif // BITCOIN_REVERSE_ITERATOR_HPP
|
Loading…
Reference in new issue