From 300851ec1690e545485e154b1a4df55bec7621ae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jorge=20Tim=C3=B3n?= <jtimon@jtimon.cc>
Date: Thu, 13 Apr 2017 00:24:40 +0200
Subject: [PATCH 1/5] 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
---
 src/Makefile.am              |  1 +
 src/checkpoints.cpp          |  1 +
 src/net_processing.cpp       |  1 +
 src/reverse_iterator.h       | 39 ++++++++++++++++++++++++++++++++++++
 src/test/prevector_tests.cpp |  1 +
 src/txmempool.cpp            |  1 +
 src/validation.cpp           |  1 +
 7 files changed, 45 insertions(+)
 create mode 100644 src/reverse_iterator.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 9b9dd89f6..a37c6a502 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -124,6 +124,7 @@ BITCOIN_CORE_H = \
   pow.h \
   protocol.h \
   random.h \
+  reverse_iterator.h \
   reverselock.h \
   rpc/blockchain.h \
   rpc/client.h \
diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp
index 13b587653..7afc6a00f 100644
--- a/src/checkpoints.cpp
+++ b/src/checkpoints.cpp
@@ -6,6 +6,7 @@
 
 #include "chain.h"
 #include "chainparams.h"
+#include "reverse_iterator.h"
 #include "validation.h"
 #include "uint256.h"
 
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index b9357440e..ce61a28da 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -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"
diff --git a/src/reverse_iterator.h b/src/reverse_iterator.h
new file mode 100644
index 000000000..409f895ce
--- /dev/null
+++ b/src/reverse_iterator.h
@@ -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
diff --git a/src/test/prevector_tests.cpp b/src/test/prevector_tests.cpp
index 11bb11d1e..7182caab9 100644
--- a/src/test/prevector_tests.cpp
+++ b/src/test/prevector_tests.cpp
@@ -5,6 +5,7 @@
 #include <vector>
 #include "prevector.h"
 
+#include "reverse_iterator.h"
 #include "serialize.h"
 #include "streams.h"
 
diff --git a/src/txmempool.cpp b/src/txmempool.cpp
index afafc695f..02a549b12 100644
--- a/src/txmempool.cpp
+++ b/src/txmempool.cpp
@@ -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"
diff --git a/src/validation.cpp b/src/validation.cpp
index bef17337b..8108da4c5 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -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"

From 33aed5bf89cf0337ab5eccadc50594930178039b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jorge=20Tim=C3=B3n?= <jtimon@jtimon.cc>
Date: Mon, 19 Jun 2017 01:45:23 +0200
Subject: [PATCH 2/5] Fix const_reverse_iterator constructor (pass const ptr)

---
 src/prevector.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/prevector.h b/src/prevector.h
index dc17e7ce4..02d860bb0 100644
--- a/src/prevector.h
+++ b/src/prevector.h
@@ -132,7 +132,7 @@ public:
         typedef const T* pointer;
         typedef const T& reference;
         typedef std::bidirectional_iterator_tag iterator_category;
-        const_reverse_iterator(T* ptr_) : ptr(ptr_) {}
+        const_reverse_iterator(const T* ptr_) : ptr(ptr_) {}
         const_reverse_iterator(reverse_iterator x) : ptr(&(*x)) {}
         const T& operator*() const { return *ptr; }
         const T* operator->() const { return ptr; }

From 3eff827f89a2dd8cc72216d1ab2add40c290517b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jorge=20Tim=C3=B3n?= <jtimon@jtimon.cc>
Date: Thu, 13 Apr 2017 00:51:39 +0200
Subject: [PATCH 3/5] scripted-diff: Remove BOOST_REVERSE_FOREACH

-BEGIN VERIFY SCRIPT-
sed -i 's/BOOST_REVERSE_FOREACH(\(.*\), \(.*\))/for (\1 : reverse_iterate(\2))/' ./src/*.h ./src/*.cpp ./src/*/*.h ./src/*/*.cpp ;
-END VERIFY SCRIPT-
---
 src/checkpoints.cpp          | 2 +-
 src/net_processing.cpp       | 4 ++--
 src/test/prevector_tests.cpp | 4 ++--
 src/txmempool.cpp            | 2 +-
 src/validation.cpp           | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp
index 7afc6a00f..54260215d 100644
--- a/src/checkpoints.cpp
+++ b/src/checkpoints.cpp
@@ -20,7 +20,7 @@ namespace Checkpoints {
     {
         const MapCheckpoints& checkpoints = data.mapCheckpoints;
 
-        BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints)
+        for (const MapCheckpoints::value_type& i : reverse_iterate(checkpoints))
         {
             const uint256& hash = i.second;
             BlockMap::const_iterator t = mapBlockIndex.find(hash);
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index ce61a28da..a8ad41dba 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -845,7 +845,7 @@ void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex *pindexNew, const CB
         // Relay inventory, but don't relay old inventory during initial block download.
         connman->ForEachNode([nNewHeight, &vHashes](CNode* pnode) {
             if (nNewHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 0)) {
-                BOOST_REVERSE_FOREACH(const uint256& hash, vHashes) {
+                for (const uint256& hash : reverse_iterate(vHashes)) {
                     pnode->PushBlockHash(hash);
                 }
             }
@@ -2356,7 +2356,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
             } else {
                 std::vector<CInv> vGetData;
                 // Download as much as possible, from earliest to latest.
-                BOOST_REVERSE_FOREACH(const CBlockIndex *pindex, vToFetch) {
+                for (const CBlockIndex *pindex : reverse_iterate(vToFetch)) {
                     if (nodestate->nBlocksInFlight >= MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
                         // Can't download any more from this peer
                         break;
diff --git a/src/test/prevector_tests.cpp b/src/test/prevector_tests.cpp
index 7182caab9..345c4a214 100644
--- a/src/test/prevector_tests.cpp
+++ b/src/test/prevector_tests.cpp
@@ -57,13 +57,13 @@ class prevector_tester {
         for (const T& v : pre_vector) {
              local_check(v == real_vector[pos++]);
         }
-        BOOST_REVERSE_FOREACH(const T& v, pre_vector) {
+        for (const T& v : reverse_iterate(pre_vector)) {
              local_check(v == real_vector[--pos]);
         }
         for (const T& v : const_pre_vector) {
              local_check(v == real_vector[pos++]);
         }
-        BOOST_REVERSE_FOREACH(const T& v, const_pre_vector) {
+        for (const T& v : reverse_iterate(const_pre_vector)) {
              local_check(v == real_vector[--pos]);
         }
         CDataStream ss1(SER_DISK, 0);
diff --git a/src/txmempool.cpp b/src/txmempool.cpp
index 02a549b12..8ba48f3bb 100644
--- a/src/txmempool.cpp
+++ b/src/txmempool.cpp
@@ -128,7 +128,7 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashes
     // This maximizes the benefit of the descendant cache and guarantees that
     // setMemPoolChildren will be updated, an assumption made in
     // UpdateForDescendants.
-    BOOST_REVERSE_FOREACH(const uint256 &hash, vHashesToUpdate) {
+    for (const uint256 &hash : reverse_iterate(vHashesToUpdate)) {
         // we cache the in-mempool children to avoid duplicate updates
         setEntries setChildren;
         // calculate children from mapNextTx
diff --git a/src/validation.cpp b/src/validation.cpp
index 8108da4c5..04d180a08 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -2217,7 +2217,7 @@ static bool ActivateBestChainStep(CValidationState& state, const CChainParams& c
         nHeight = nTargetHeight;
 
         // Connect new blocks.
-        BOOST_REVERSE_FOREACH(CBlockIndex *pindexConnect, vpindexToConnect) {
+        for (CBlockIndex *pindexConnect : reverse_iterate(vpindexToConnect)) {
             if (!ConnectTip(state, chainparams, pindexConnect, pindexConnect == pindexMostWork ? pblock : std::shared_ptr<const CBlock>(), connectTrace, disconnectpool)) {
                 if (state.IsInvalid()) {
                     // The block violates a consensus rule.

From 5995735c5be19bee4c5369bd1861e913cf201db7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jorge=20Tim=C3=B3n?= <jtimon@jtimon.cc>
Date: Thu, 13 Apr 2017 01:08:18 +0200
Subject: [PATCH 4/5] scripted-diff: Remove #include <boost/foreach.hpp>

-BEGIN VERIFY SCRIPT-
sed -i ':a;N;$!ba;s/#include <boost\/foreach.hpp>\n//' ./src/*.h ./src/*.cpp ./src/*/*.h ./src/*/*.cpp ./src/*/*/*.h ./src/*/*/*.cpp
-END VERIFY SCRIPT-
---
 src/bench/coin_selection.cpp         | 1 -
 src/bloom.cpp                        | 1 -
 src/checkpoints.cpp                  | 1 -
 src/checkqueue.h                     | 1 -
 src/core_write.cpp                   | 1 -
 src/httprpc.cpp                      | 1 -
 src/memusage.h                       | 1 -
 src/net.h                            | 1 -
 src/policy/policy.cpp                | 1 -
 src/qt/addresstablemodel.cpp         | 1 -
 src/qt/recentrequeststablemodel.cpp  | 1 -
 src/qt/transactionrecord.cpp         | 1 -
 src/qt/walletmodel.cpp               | 1 -
 src/rpc/net.cpp                      | 1 -
 src/rpc/server.cpp                   | 1 -
 src/script/ismine.cpp                | 1 -
 src/script/sign.cpp                  | 1 -
 src/script/standard.cpp              | 1 -
 src/sync.cpp                         | 1 -
 src/test/getarg_tests.cpp            | 1 -
 src/test/multisig_tests.cpp          | 1 -
 src/test/script_tests.cpp            | 1 -
 src/test/transaction_tests.cpp       | 1 -
 src/timedata.cpp                     | 1 -
 src/torcontrol.cpp                   | 1 -
 src/wallet/crypter.cpp               | 1 -
 src/wallet/db.cpp                    | 1 -
 src/wallet/rpcdump.cpp               | 1 -
 src/wallet/test/accounting_tests.cpp | 1 -
 src/wallet/walletdb.cpp              | 1 -
 30 files changed, 30 deletions(-)

diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp
index 942942c29..f8956508f 100644
--- a/src/bench/coin_selection.cpp
+++ b/src/bench/coin_selection.cpp
@@ -5,7 +5,6 @@
 #include "bench.h"
 #include "wallet/wallet.h"
 
-#include <boost/foreach.hpp>
 #include <set>
 
 static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<COutput>& vCoins)
diff --git a/src/bloom.cpp b/src/bloom.cpp
index cc3baa918..fa884f0bf 100644
--- a/src/bloom.cpp
+++ b/src/bloom.cpp
@@ -14,7 +14,6 @@
 #include <math.h>
 #include <stdlib.h>
 
-#include <boost/foreach.hpp>
 
 #define LN2SQUARED 0.4804530139182014246671025263266649717305529515945455
 #define LN2 0.6931471805599453094172321214581765680755001343602552
diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp
index 54260215d..e6b5fb72a 100644
--- a/src/checkpoints.cpp
+++ b/src/checkpoints.cpp
@@ -12,7 +12,6 @@
 
 #include <stdint.h>
 
-#include <boost/foreach.hpp>
 
 namespace Checkpoints {
 
diff --git a/src/checkqueue.h b/src/checkqueue.h
index d7b7b836d..408e278d2 100644
--- a/src/checkqueue.h
+++ b/src/checkqueue.h
@@ -10,7 +10,6 @@
 #include <algorithm>
 #include <vector>
 
-#include <boost/foreach.hpp>
 #include <boost/thread/condition_variable.hpp>
 #include <boost/thread/mutex.hpp>
 
diff --git a/src/core_write.cpp b/src/core_write.cpp
index 553ef4487..7f38e9e56 100644
--- a/src/core_write.cpp
+++ b/src/core_write.cpp
@@ -15,7 +15,6 @@
 #include "utilmoneystr.h"
 #include "utilstrencodings.h"
 
-#include <boost/foreach.hpp>
 
 std::string FormatScript(const CScript& script)
 {
diff --git a/src/httprpc.cpp b/src/httprpc.cpp
index 053702f84..39da26afe 100644
--- a/src/httprpc.cpp
+++ b/src/httprpc.cpp
@@ -18,7 +18,6 @@
 #include <stdio.h>
 
 #include <boost/algorithm/string.hpp> // boost::trim
-#include <boost/foreach.hpp>
 
 /** WWW-Authenticate to present with 401 Unauthorized response */
 static const char* WWW_AUTH_HEADER_DATA = "Basic realm=\"jsonrpc\"";
diff --git a/src/memusage.h b/src/memusage.h
index 710120d28..93fd6a0eb 100644
--- a/src/memusage.h
+++ b/src/memusage.h
@@ -15,7 +15,6 @@
 #include <unordered_map>
 #include <unordered_set>
 
-#include <boost/foreach.hpp>
 
 namespace memusage
 {
diff --git a/src/net.h b/src/net.h
index a6aea189f..704ef0563 100644
--- a/src/net.h
+++ b/src/net.h
@@ -33,7 +33,6 @@
 #include <arpa/inet.h>
 #endif
 
-#include <boost/foreach.hpp>
 #include <boost/signals2/signal.hpp>
 
 class CScheduler;
diff --git a/src/policy/policy.cpp b/src/policy/policy.cpp
index 5f68c09a8..2f78d2f34 100644
--- a/src/policy/policy.cpp
+++ b/src/policy/policy.cpp
@@ -13,7 +13,6 @@
 #include "util.h"
 #include "utilstrencodings.h"
 
-#include <boost/foreach.hpp>
 
 CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)
 {
diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp
index d3ad24da0..2fa032abd 100644
--- a/src/qt/addresstablemodel.cpp
+++ b/src/qt/addresstablemodel.cpp
@@ -10,7 +10,6 @@
 #include "base58.h"
 #include "wallet/wallet.h"
 
-#include <boost/foreach.hpp>
 
 #include <QFont>
 #include <QDebug>
diff --git a/src/qt/recentrequeststablemodel.cpp b/src/qt/recentrequeststablemodel.cpp
index 470fb6b37..4e88c8802 100644
--- a/src/qt/recentrequeststablemodel.cpp
+++ b/src/qt/recentrequeststablemodel.cpp
@@ -11,7 +11,6 @@
 #include "clientversion.h"
 #include "streams.h"
 
-#include <boost/foreach.hpp>
 
 RecentRequestsTableModel::RecentRequestsTableModel(CWallet *wallet, WalletModel *parent) :
     QAbstractTableModel(parent), walletModel(parent)
diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp
index da070da08..03fd734e9 100644
--- a/src/qt/transactionrecord.cpp
+++ b/src/qt/transactionrecord.cpp
@@ -12,7 +12,6 @@
 
 #include <stdint.h>
 
-#include <boost/foreach.hpp>
 
 /* Return positive answer if transaction should be shown in list.
  */
diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp
index 449eb1ae5..2b635e018 100644
--- a/src/qt/walletmodel.cpp
+++ b/src/qt/walletmodel.cpp
@@ -34,7 +34,6 @@
 #include <QSet>
 #include <QTimer>
 
-#include <boost/foreach.hpp>
 
 WalletModel::WalletModel(const PlatformStyle *platformStyle, CWallet *_wallet, OptionsModel *_optionsModel, QObject *parent) :
     QObject(parent), wallet(_wallet), optionsModel(_optionsModel), addressTableModel(0),
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp
index d6f9f0059..c52ea7584 100644
--- a/src/rpc/net.cpp
+++ b/src/rpc/net.cpp
@@ -19,7 +19,6 @@
 #include "utilstrencodings.h"
 #include "version.h"
 
-#include <boost/foreach.hpp>
 
 #include <univalue.h>
 
diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp
index 1a04ce2b4..6f7ab437b 100644
--- a/src/rpc/server.cpp
+++ b/src/rpc/server.cpp
@@ -17,7 +17,6 @@
 #include <univalue.h>
 
 #include <boost/bind.hpp>
-#include <boost/foreach.hpp>
 #include <boost/signals2/signal.hpp>
 #include <boost/algorithm/string/case_conv.hpp> // for to_upper()
 #include <boost/algorithm/string/classification.hpp>
diff --git a/src/script/ismine.cpp b/src/script/ismine.cpp
index 35b534344..0a3961973 100644
--- a/src/script/ismine.cpp
+++ b/src/script/ismine.cpp
@@ -11,7 +11,6 @@
 #include "script/standard.h"
 #include "script/sign.h"
 
-#include <boost/foreach.hpp>
 
 typedef std::vector<unsigned char> valtype;
 
diff --git a/src/script/sign.cpp b/src/script/sign.cpp
index f4a32472b..94120e640 100644
--- a/src/script/sign.cpp
+++ b/src/script/sign.cpp
@@ -12,7 +12,6 @@
 #include "script/standard.h"
 #include "uint256.h"
 
-#include <boost/foreach.hpp>
 
 typedef std::vector<unsigned char> valtype;
 
diff --git a/src/script/standard.cpp b/src/script/standard.cpp
index 7efcad7b0..3415a1ad7 100644
--- a/src/script/standard.cpp
+++ b/src/script/standard.cpp
@@ -10,7 +10,6 @@
 #include "util.h"
 #include "utilstrencodings.h"
 
-#include <boost/foreach.hpp>
 
 typedef std::vector<unsigned char> valtype;
 
diff --git a/src/sync.cpp b/src/sync.cpp
index 94f2cafa9..c359e8220 100644
--- a/src/sync.cpp
+++ b/src/sync.cpp
@@ -9,7 +9,6 @@
 
 #include <stdio.h>
 
-#include <boost/foreach.hpp>
 #include <boost/thread.hpp>
 
 #ifdef DEBUG_LOCKCONTENTION
diff --git a/src/test/getarg_tests.cpp b/src/test/getarg_tests.cpp
index 01cc5ed83..c79675f5a 100644
--- a/src/test/getarg_tests.cpp
+++ b/src/test/getarg_tests.cpp
@@ -9,7 +9,6 @@
 #include <vector>
 
 #include <boost/algorithm/string.hpp>
-#include <boost/foreach.hpp>
 #include <boost/test/unit_test.hpp>
 
 BOOST_FIXTURE_TEST_SUITE(getarg_tests, BasicTestingSetup)
diff --git a/src/test/multisig_tests.cpp b/src/test/multisig_tests.cpp
index 6d8aab887..c686f679c 100644
--- a/src/test/multisig_tests.cpp
+++ b/src/test/multisig_tests.cpp
@@ -14,7 +14,6 @@
 #include "test/test_bitcoin.h"
 
 
-#include <boost/foreach.hpp>
 #include <boost/test/unit_test.hpp>
 
 typedef std::vector<unsigned char> valtype;
diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp
index 2ff4f4227..4ddea9bae 100644
--- a/src/test/script_tests.cpp
+++ b/src/test/script_tests.cpp
@@ -24,7 +24,6 @@
 #include <string>
 #include <vector>
 
-#include <boost/foreach.hpp>
 #include <boost/test/unit_test.hpp>
 
 #include <univalue.h>
diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp
index 778d2fd74..39f9f5860 100644
--- a/src/test/transaction_tests.cpp
+++ b/src/test/transaction_tests.cpp
@@ -27,7 +27,6 @@
 #include <boost/algorithm/string/classification.hpp>
 #include <boost/algorithm/string/split.hpp>
 #include <boost/test/unit_test.hpp>
-#include <boost/foreach.hpp>
 
 #include <univalue.h>
 
diff --git a/src/timedata.cpp b/src/timedata.cpp
index d736baa21..099ed7f04 100644
--- a/src/timedata.cpp
+++ b/src/timedata.cpp
@@ -15,7 +15,6 @@
 #include "utilstrencodings.h"
 #include "warnings.h"
 
-#include <boost/foreach.hpp>
 
 static CCriticalSection cs_nTimeOffset;
 static int64_t nTimeOffset = 0;
diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp
index 188300516..f27342862 100644
--- a/src/torcontrol.cpp
+++ b/src/torcontrol.cpp
@@ -17,7 +17,6 @@
 
 #include <boost/bind.hpp>
 #include <boost/signals2/signal.hpp>
-#include <boost/foreach.hpp>
 #include <boost/algorithm/string/split.hpp>
 #include <boost/algorithm/string/classification.hpp>
 #include <boost/algorithm/string/replace.hpp>
diff --git a/src/wallet/crypter.cpp b/src/wallet/crypter.cpp
index 836c15b82..33be47273 100644
--- a/src/wallet/crypter.cpp
+++ b/src/wallet/crypter.cpp
@@ -12,7 +12,6 @@
 
 #include <string>
 #include <vector>
-#include <boost/foreach.hpp>
 
 int CCrypter::BytesToKeySHA512AES(const std::vector<unsigned char>& chSalt, const SecureString& strKeyData, int count, unsigned char *key,unsigned char *iv) const
 {
diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp
index 844d61079..3f495f23b 100644
--- a/src/wallet/db.cpp
+++ b/src/wallet/db.cpp
@@ -18,7 +18,6 @@
 #include <sys/stat.h>
 #endif
 
-#include <boost/foreach.hpp>
 #include <boost/thread.hpp>
 
 //
diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp
index 3c2536464..7627d625d 100644
--- a/src/wallet/rpcdump.cpp
+++ b/src/wallet/rpcdump.cpp
@@ -26,7 +26,6 @@
 
 #include <univalue.h>
 
-#include <boost/foreach.hpp>
 
 std::string static EncodeDumpTime(int64_t nTime) {
     return DateTimeStrFormat("%Y-%m-%dT%H:%M:%SZ", nTime);
diff --git a/src/wallet/test/accounting_tests.cpp b/src/wallet/test/accounting_tests.cpp
index 12d9f2e99..330878ceb 100644
--- a/src/wallet/test/accounting_tests.cpp
+++ b/src/wallet/test/accounting_tests.cpp
@@ -8,7 +8,6 @@
 
 #include <stdint.h>
 
-#include <boost/foreach.hpp>
 #include <boost/test/unit_test.hpp>
 
 extern CWallet* pwalletMain;
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp
index eca6706c0..bf4798264 100644
--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -18,7 +18,6 @@
 
 #include <atomic>
 
-#include <boost/foreach.hpp>
 #include <boost/thread.hpp>
 
 //

From b1268a19d0b80401339ede2188abbd389f8d7fb0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jorge=20Tim=C3=B3n?= <jtimon@jtimon.cc>
Date: Thu, 1 Jun 2017 22:35:42 +0200
Subject: [PATCH 5/5] clang-format: Delete ForEachMacros

---
 src/.clang-format | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/.clang-format b/src/.clang-format
index fc5350913..9a700b750 100644
--- a/src/.clang-format
+++ b/src/.clang-format
@@ -23,7 +23,6 @@ ContinuationIndentWidth: 4
 Cpp11BracedListStyle: true
 DerivePointerAlignment: false
 DisableFormat:   false
-ForEachMacros:   [ foreach, Q_FOREACH, BOOST_FOREACH, BOOST_REVERSE_FOREACH ]
 IndentCaseLabels: false
 IndentFunctionDeclarationAfterType: false
 IndentWidth:     4