Skip to content

Commit 2e6aa1b

Browse files
authored
Merge pull request #525 from mxaddict/patch-27
Replaced all BOOST_FOREACH calls with new for() syntax (c++11)
2 parents 0a8c872 + 664b959 commit 2e6aa1b

64 files changed

Lines changed: 396 additions & 518 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/bloom.cpp‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#include <math.h>
1515
#include <stdlib.h>
1616

17-
#include <boost/foreach.hpp>
18-
1917
#define LN2SQUARED 0.4804530139182014246671025263266649717305529515945455
2018
#define LN2 0.6931471805599453094172321214581765680755001343602552
2119

@@ -151,7 +149,7 @@ bool CBloomFilter::IsRelevantAndUpdate(const CTransaction& tx)
151149
const CTxOut& txout = tx.vout[i];
152150
// Match if the filter contains any arbitrary script data element in any scriptPubKey in tx
153151
// If this matches, also add the specific output that was matched.
154-
// This means clients don't have to update the filter themselves when a new relevant tx
152+
// This means clients don't have to update the filter themselves when a new relevant tx
155153
// is discovered in order to find spending transactions, which avoids round-tripping and race conditions.
156154
CScript::const_iterator pc = txout.scriptPubKey.begin();
157155
vector<unsigned char> data;
@@ -181,7 +179,7 @@ bool CBloomFilter::IsRelevantAndUpdate(const CTransaction& tx)
181179
if (fFound)
182180
return true;
183181

184-
BOOST_FOREACH(const CTxIn& txin, tx.vin)
182+
for(const CTxIn& txin: tx.vin)
185183
{
186184
// Match if the filter contains an outpoint tx spends
187185
if (contains(txin.prevout))

‎src/checkpoints.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include <stdint.h>
1313

14-
#include <boost/foreach.hpp>
14+
#include <boost/range/adaptor/reversed.hpp>
1515

1616
namespace Checkpoints {
1717

@@ -69,7 +69,7 @@ namespace Checkpoints {
6969
{
7070
const MapCheckpoints& checkpoints = data.mapCheckpoints;
7171

72-
BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, checkpoints)
72+
for(const MapCheckpoints::value_type& i: boost::adaptors::reverse(checkpoints))
7373
{
7474
const uint256& hash = i.second;
7575
BlockMap::const_iterator t = mapBlockIndex.find(hash);

‎src/checkqueue.h‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
#include <algorithm>
99
#include <vector>
1010

11-
#include <boost/foreach.hpp>
1211
#include <boost/thread/condition_variable.hpp>
1312
#include <boost/thread/locks.hpp>
1413
#include <boost/thread/mutex.hpp>
1514

1615
template <typename T>
1716
class CCheckQueueControl;
1817

19-
/**
18+
/**
2019
* Queue for verifications that have to be performed.
2120
* The verifications are represented by a type T, which must provide an
2221
* operator(), returning a bool.
@@ -119,7 +118,7 @@ class CCheckQueue
119118
fOk = fAllOk;
120119
}
121120
// execute work
122-
BOOST_FOREACH (T& check, vChecks)
121+
for(T& check: vChecks)
123122
if (fOk)
124123
fOk = check();
125124
vChecks.clear();
@@ -146,7 +145,7 @@ class CCheckQueue
146145
void Add(std::vector<T>& vChecks)
147146
{
148147
boost::unique_lock<boost::mutex> lock(mutex);
149-
BOOST_FOREACH (T& check, vChecks) {
148+
for(T& check: vChecks) {
150149
queue.push_back(T());
151150
check.swap(queue.back());
152151
}
@@ -169,7 +168,7 @@ class CCheckQueue
169168

170169
};
171170

172-
/**
171+
/**
173172
* RAII-style controller object for a CCheckQueue that guarantees the passed
174173
* queue is finished before continuing.
175174
*/

‎src/coins.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void CCoins::CalcMaskSize(unsigned int &nBytes, unsigned int &nNonzeroBytes) con
3434
nBytes += nLastUsedByte;
3535
}
3636

37-
bool CCoins::Spend(uint32_t nPos)
37+
bool CCoins::Spend(uint32_t nPos)
3838
{
3939
if (nPos >= vout.size() || vout[nPos].IsNull())
4040
return false;
@@ -451,7 +451,7 @@ double CCoinsViewCache::GetPriority(const CTransaction &tx, int nHeight, CAmount
451451
if (tx.IsCoinBase())
452452
return 0.0;
453453
double dResult = 0.0;
454-
BOOST_FOREACH(const CTxIn& txin, tx.vin)
454+
for(const CTxIn& txin: tx.vin)
455455
{
456456
const CCoins* coins = AccessCoins(txin.prevout.hash);
457457
assert(coins);

‎src/coins.h‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
#include <assert.h>
1717
#include <stdint.h>
1818

19-
#include <boost/foreach.hpp>
2019
#include <boost/unordered_map.hpp>
2120

2221
using namespace CFund;
2322

24-
/**
23+
/**
2524
* Pruned version of CTransaction: only retains metadata and unspent transaction outputs
2625
*
2726
* Serialized format:
@@ -124,7 +123,7 @@ class CCoins
124123
}
125124

126125
void ClearUnspendable() {
127-
BOOST_FOREACH(CTxOut &txout, vout) {
126+
for(CTxOut &txout: vout) {
128127
if (txout.scriptPubKey.IsUnspendable())
129128
txout.SetNull();
130129
}
@@ -260,15 +259,15 @@ class CCoins
260259
//! check whether the entire CCoins is spent
261260
//! note that only !IsPruned() CCoins can be serialized
262261
bool IsPruned() const {
263-
BOOST_FOREACH(const CTxOut &out, vout)
262+
for(const CTxOut &out: vout)
264263
if (!out.IsNull())
265264
return false;
266265
return true;
267266
}
268267

269268
size_t DynamicMemoryUsage() const {
270269
size_t ret = memusage::DynamicUsage(vout);
271-
BOOST_FOREACH(const CTxOut &out, vout) {
270+
for(const CTxOut &out: vout) {
272271
ret += RecursiveDynamicUsage(out.scriptPubKey);
273272
}
274273
return ret;

‎src/core_write.cpp‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "utilstrencodings.h"
1717

1818
#include <boost/assign/list_of.hpp>
19-
#include <boost/foreach.hpp>
2019

2120
using namespace std;
2221

@@ -157,7 +156,7 @@ void ScriptPubKeyToUniv(const CScript& scriptPubKey,
157156
out.pushKV("type", GetTxnOutputType(type));
158157

159158
UniValue a(UniValue::VARR);
160-
BOOST_FOREACH(const CTxDestination& addr, addresses)
159+
for(const CTxDestination& addr: addresses)
161160
a.push_back(CNavCoinAddress(addr).ToString());
162161
out.pushKV("addresses", a);
163162
}
@@ -170,7 +169,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry)
170169
entry.pushKV("time", (int64_t)tx.nTime);
171170

172171
UniValue vin(UniValue::VARR);
173-
BOOST_FOREACH(const CTxIn& txin, tx.vin) {
172+
for(const CTxIn& txin: tx.vin) {
174173
UniValue in(UniValue::VOBJ);
175174
if (tx.IsCoinBase())
176175
in.pushKV("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()));

‎src/httprpc.cpp‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "utilstrencodings.h"
2020

2121
#include <boost/algorithm/string.hpp> // boost::trim
22-
#include <boost/foreach.hpp> //BOOST_FOREACH
2322

2423
/** WWW-Authenticate to present with 401 Unauthorized response */
2524
static const char* WWW_AUTH_HEADER_DATA = "Basic realm=\"jsonrpc\"";
@@ -86,7 +85,7 @@ static void JSONErrorReply(HTTPRequest* req, const UniValue& objError, const Uni
8685
//This function checks username and password against -rpcauth
8786
//entries from config file.
8887
static bool multiUserAuthorized(std::string strUserPass)
89-
{
88+
{
9089
if (strUserPass.find(":") == std::string::npos) {
9190
return false;
9291
}
@@ -95,7 +94,7 @@ static bool multiUserAuthorized(std::string strUserPass)
9594

9695
if (mapMultiArgs.count("-rpcauth") > 0) {
9796
//Search for multi-user login/pass "rpcauth" from config
98-
BOOST_FOREACH(std::string strRPCAuth, mapMultiArgs["-rpcauth"])
97+
for(std::string strRPCAuth: mapMultiArgs["-rpcauth"])
9998
{
10099
std::vector<std::string> vFields;
101100
boost::split(vFields, strRPCAuth, boost::is_any_of(":$"));
@@ -113,8 +112,8 @@ static bool multiUserAuthorized(std::string strUserPass)
113112
std::string strHash = vFields[2];
114113

115114
unsigned int KEY_SIZE = 32;
116-
unsigned char *out = new unsigned char[KEY_SIZE];
117-
115+
unsigned char *out = new unsigned char[KEY_SIZE];
116+
118117
CHMAC_SHA256(reinterpret_cast<const unsigned char*>(strSalt.c_str()), strSalt.size()).Write(reinterpret_cast<const unsigned char*>(strPass.c_str()), strPass.size()).Finalize(out);
119118
std::vector<unsigned char> hexvec(out, out+KEY_SIZE);
120119
std::string strHashFromPass = HexStr(hexvec);
@@ -136,7 +135,7 @@ static bool RPCAuthorized(const std::string& strAuth)
136135
std::string strUserPass64 = strAuth.substr(6);
137136
boost::trim(strUserPass64);
138137
std::string strUserPass = DecodeBase64(strUserPass64);
139-
138+
140139
//Check if authorized under single-user field
141140
if (TimingResistantEqual(strUserPass, strRPCUserColonPass)) {
142141
return true;

‎src/httpserver.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static bool ClientAllowed(const CNetAddr& netaddr)
189189
{
190190
if (!netaddr.IsValid())
191191
return false;
192-
BOOST_FOREACH (const CSubNet& subnet, rpc_allow_subnets)
192+
for(const CSubNet& subnet: rpc_allow_subnets)
193193
if (subnet.Match(netaddr))
194194
return true;
195195
return false;
@@ -203,7 +203,7 @@ static bool InitHTTPAllowList()
203203
rpc_allow_subnets.push_back(CSubNet("::1")); // always allow IPv6 localhost
204204
if (mapMultiArgs.count("-rpcallowip")) {
205205
const std::vector<std::string>& vAllow = mapMultiArgs["-rpcallowip"];
206-
BOOST_FOREACH (std::string strAllow, vAllow) {
206+
for(std::string strAllow: vAllow) {
207207
CSubNet subnet(strAllow);
208208
if (!subnet.IsValid()) {
209209
uiInterface.ThreadSafeMessageBox(
@@ -215,7 +215,7 @@ static bool InitHTTPAllowList()
215215
}
216216
}
217217
std::string strAllowed;
218-
BOOST_FOREACH (const CSubNet& subnet, rpc_allow_subnets)
218+
for(const CSubNet& subnet: rpc_allow_subnets)
219219
strAllowed += subnet.ToString() + " ";
220220
LogPrint("http", "Allowing HTTP connections from: %s\n", strAllowed);
221221
return true;
@@ -456,7 +456,7 @@ void InterruptHTTPServer()
456456
LogPrint("http", "Interrupting HTTP server\n");
457457
if (eventHTTP) {
458458
// Unlisten sockets
459-
BOOST_FOREACH (evhttp_bound_socket *socket, boundSockets) {
459+
for(evhttp_bound_socket *socket: boundSockets) {
460460
evhttp_del_accept_socket(eventHTTP, socket);
461461
}
462462
// Reject requests on current connections

‎src/init.cpp‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ void CleanupBlockRevFiles()
675675
// keeping a separate counter. Once we hit a gap (or if 0 doesn't exist)
676676
// start removing block files.
677677
int nContigCounter = 0;
678-
BOOST_FOREACH(const PAIRTYPE(string, path)& item, mapBlockFiles) {
678+
for(const PAIRTYPE(string, path)& item: mapBlockFiles) {
679679
if (atoi(item.first) == nContigCounter) {
680680
nContigCounter++;
681681
continue;
@@ -726,7 +726,7 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
726726
}
727727

728728
// -loadblock=
729-
BOOST_FOREACH(const boost::filesystem::path& path, vImportFiles) {
729+
for(const boost::filesystem::path& path: vImportFiles) {
730730
FILE *file = fopen(path.string().c_str(), "rb");
731731
if (file) {
732732
LogPrintf("Importing blocks file %s...\n", path.string());
@@ -1366,7 +1366,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
13661366

13671367
// sanitize comments per BIP-0014, format user agent and check total size
13681368
std::vector<string> uacomments;
1369-
BOOST_FOREACH(string cmt, mapMultiArgs["-uacomment"])
1369+
for(string cmt: mapMultiArgs["-uacomment"])
13701370
{
13711371
if (cmt != SanitizeString(cmt, SAFE_CHARS_UA_COMMENT))
13721372
return InitError(strprintf(_("User Agent comment (%s) contains unsafe characters."), cmt));
@@ -1380,7 +1380,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
13801380

13811381
if (mapArgs.count("-onlynet")) {
13821382
std::set<enum Network> nets;
1383-
BOOST_FOREACH(const std::string& snet, mapMultiArgs["-onlynet"]) {
1383+
for(const std::string& snet: mapMultiArgs["-onlynet"]) {
13841384
enum Network net = ParseNetwork(snet);
13851385
if (net == NET_UNROUTABLE)
13861386
return InitError(strprintf(_("Unknown network specified in -onlynet: '%s'"), snet));
@@ -1394,7 +1394,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
13941394
}
13951395

13961396
if (mapArgs.count("-whitelist")) {
1397-
BOOST_FOREACH(const std::string& net, mapMultiArgs["-whitelist"]) {
1397+
for(const std::string& net: mapMultiArgs["-whitelist"]) {
13981398
CSubNet subnet(net);
13991399
if (!subnet.IsValid())
14001400
return InitError(strprintf(_("Invalid netmask specified in -whitelist: '%s'"), net));
@@ -1444,13 +1444,13 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
14441444
bool fBound = false;
14451445
if (fListen) {
14461446
if (mapArgs.count("-bind") || mapArgs.count("-whitebind")) {
1447-
BOOST_FOREACH(const std::string& strBind, mapMultiArgs["-bind"]) {
1447+
for(const std::string& strBind: mapMultiArgs["-bind"]) {
14481448
CService addrBind;
14491449
if (!Lookup(strBind.c_str(), addrBind, GetListenPort(), false))
14501450
return InitError(ResolveErrMsg("bind", strBind));
14511451
fBound |= Bind(addrBind, (BF_EXPLICIT | BF_REPORT_ERROR));
14521452
}
1453-
BOOST_FOREACH(const std::string& strBind, mapMultiArgs["-whitebind"]) {
1453+
for(const std::string& strBind: mapMultiArgs["-whitebind"]) {
14541454
CService addrBind;
14551455
if (!Lookup(strBind.c_str(), addrBind, 0, false))
14561456
return InitError(ResolveErrMsg("whitebind", strBind));
@@ -1470,7 +1470,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
14701470
}
14711471

14721472
if (mapArgs.count("-externalip")) {
1473-
BOOST_FOREACH(const std::string& strAddr, mapMultiArgs["-externalip"]) {
1473+
for(const std::string& strAddr: mapMultiArgs["-externalip"]) {
14741474
CService addrLocal;
14751475
if (Lookup(strAddr.c_str(), addrLocal, GetListenPort(), fNameLookup) && addrLocal.IsValid())
14761476
AddLocal(addrLocal, LOCAL_MANUAL);
@@ -1479,7 +1479,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
14791479
}
14801480
}
14811481

1482-
BOOST_FOREACH(const std::string& strDest, mapMultiArgs["-seednode"])
1482+
for(const std::string& strDest: mapMultiArgs["-seednode"])
14831483
AddOneShot(strDest);
14841484

14851485
#if ENABLE_ZMQ
@@ -1785,7 +1785,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
17851785
std::vector<boost::filesystem::path> vImportFiles;
17861786
if (mapArgs.count("-loadblock"))
17871787
{
1788-
BOOST_FOREACH(const std::string& strFile, mapMultiArgs["-loadblock"])
1788+
for(const std::string& strFile: mapMultiArgs["-loadblock"])
17891789
vImportFiles.push_back(strFile);
17901790
}
17911791
threadGroup.create_thread(boost::bind(&ThreadImport, vImportFiles));

‎src/keystore.cpp‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include "pubkey.h"
1010
#include "util.h"
1111

12-
#include <boost/foreach.hpp>
13-
1412
bool CKeyStore::AddKey(const CKey &key) {
1513
return AddKeyPubKey(key, key.GetPubKey());
1614
}

0 commit comments

Comments
 (0)