mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 20:42:59 +01:00
c49e506176
-BEGIN VERIFY SCRIPT- sed --in-place'' --regexp-extended 's/[[:space:]]+$//g' $(git grep -I --files-with-matches --extended-regexp '[[:space:]]+$' -- src test ':!*.svg' ':!src/crypto/sha256_sse4*' ':!src/leveldb' ':!src/qt/locale' ':!src/secp256k1' ':!src/univalue') -END VERIFY SCRIPT- Signed-off-by: pasta <pasta@dashboost.org>
40 lines
762 B
C++
40 lines
762 B
C++
// Taken from https://gist.github.com/arvidsson/7231973
|
|
|
|
#ifndef BITCOIN_REVERSE_ITERATOR_H
|
|
#define BITCOIN_REVERSE_ITERATOR_H
|
|
|
|
/**
|
|
* 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 &m_x;
|
|
|
|
public:
|
|
explicit reverse_range(T &x) : m_x(x) {}
|
|
|
|
auto begin() const -> decltype(this->m_x.rbegin())
|
|
{
|
|
return m_x.rbegin();
|
|
}
|
|
|
|
auto end() const -> decltype(this->m_x.rend())
|
|
{
|
|
return m_x.rend();
|
|
}
|
|
};
|
|
|
|
template <typename T>
|
|
reverse_range<T> reverse_iterate(T &x)
|
|
{
|
|
return reverse_range<T>(x);
|
|
}
|
|
|
|
#endif // BITCOIN_REVERSE_ITERATOR_H
|