mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
b6bde7322c
672f7ad747ecc6e04472f96fa88332be1f39d39b doc: remove usages of C++11 (fanquake) Pull request description: These were new in C++11, and now they are just our standard library. ACKs for top commit: jarolrod: re-ACK 672f7ad747ecc6e04472f96fa88332be1f39d39b hebasto: re-ACK 672f7ad747ecc6e04472f96fa88332be1f39d39b Tree-SHA512: 7e3b8b0346ba29b19e6d8536700ca510e2b543cdeecd9e740bba71ea6d0133dd96cdaeaa00f371f8ef85913ff5aaabe12878255f393dac7d354a8b89b58d050a
40 lines
756 B
C++
40 lines
756 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 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
|