Introduce src/reverse_iterator.hpp and include it...
...where it will be needed Taken from https://gist.github.com/arvidsson/7231973 with small modifications to fit the bitcoin core project
This commit is contained in:
parent
1ad3d4e126
commit
300851ec16
7 changed files with 45 additions and 0 deletions
|
@ -124,6 +124,7 @@ BITCOIN_CORE_H = \
|
|||
pow.h \
|
||||
protocol.h \
|
||||
random.h \
|
||||
reverse_iterator.h \
|
||||
reverselock.h \
|
||||
rpc/blockchain.h \
|
||||
rpc/client.h \
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "chain.h"
|
||||
#include "chainparams.h"
|
||||
#include "reverse_iterator.h"
|
||||
#include "validation.h"
|
||||
#include "uint256.h"
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "primitives/block.h"
|
||||
#include "primitives/transaction.h"
|
||||
#include "random.h"
|
||||
#include "reverse_iterator.h"
|
||||
#include "tinyformat.h"
|
||||
#include "txmempool.h"
|
||||
#include "ui_interface.h"
|
||||
|
|
39
src/reverse_iterator.h
Normal file
39
src/reverse_iterator.h
Normal file
|
@ -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
|
|
@ -5,6 +5,7 @@
|
|||
#include <vector>
|
||||
#include "prevector.h"
|
||||
|
||||
#include "reverse_iterator.h"
|
||||
#include "serialize.h"
|
||||
#include "streams.h"
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "validation.h"
|
||||
#include "policy/policy.h"
|
||||
#include "policy/fees.h"
|
||||
#include "reverse_iterator.h"
|
||||
#include "streams.h"
|
||||
#include "timedata.h"
|
||||
#include "util.h"
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "primitives/block.h"
|
||||
#include "primitives/transaction.h"
|
||||
#include "random.h"
|
||||
#include "reverse_iterator.h"
|
||||
#include "script/script.h"
|
||||
#include "script/sigcache.h"
|
||||
#include "script/standard.h"
|
||||
|
|
Loading…
Reference in a new issue