diff --git a/src/addrman.h b/src/addrman.h --- a/src/addrman.h +++ b/src/addrman.h @@ -344,9 +344,9 @@ s << nUBuckets; std::map mapUnkIds; int nIds = 0; - for (const std::pair p : mapInfo) { - mapUnkIds[p.first] = nIds; - const CAddrInfo &info = p.second; + for (const auto &entry : mapInfo) { + mapUnkIds[entry.first] = nIds; + const CAddrInfo &info = entry.second; if (info.nRefCount) { // this means nNew was wrong, oh ow assert(nIds != nNew); @@ -355,8 +355,8 @@ } } nIds = 0; - for (const std::pair p : mapInfo) { - const CAddrInfo &info = p.second; + for (const auto &entry : mapInfo) { + const CAddrInfo &info = entry.second; if (info.fInTried) { // this means nTried was wrong, oh ow assert(nIds != nTried); diff --git a/src/addrman.cpp b/src/addrman.cpp --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -464,10 +464,9 @@ return -7; } - for (std::map::iterator it = mapInfo.begin(); - it != mapInfo.end(); it++) { - int n = (*it).first; - CAddrInfo &info = (*it).second; + for (const auto &entry : mapInfo) { + int n = entry.first; + const CAddrInfo &info = entry.second; if (info.fInTried) { if (!info.nLastSuccess) { return -1; diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -73,10 +73,10 @@ cachedWallet.clear(); LOCK2(cs_main, wallet->cs_wallet); - for (const std::pair &p : wallet->mapWallet) { - if (TransactionRecord::showTransaction(p.second)) { - cachedWallet.append( - TransactionRecord::decomposeTransaction(wallet, p.second)); + for (const auto &entry : wallet->mapWallet) { + if (TransactionRecord::showTransaction(entry.second)) { + cachedWallet.append(TransactionRecord::decomposeTransaction( + wallet, entry.second)); } } } diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -717,10 +717,10 @@ g_connman->GetBanned(banMap); UniValue bannedAddresses(UniValue::VARR); - for (banmap_t::iterator it = banMap.begin(); it != banMap.end(); it++) { - CBanEntry banEntry = (*it).second; + for (const auto &entry : banMap) { + const CBanEntry &banEntry = entry.second; UniValue rec(UniValue::VOBJ); - rec.pushKV("address", (*it).first.ToString()); + rec.pushKV("address", entry.first.ToString()); rec.pushKV("banned_until", banEntry.nBanUntil); rec.pushKV("ban_created", banEntry.nCreateTime); rec.pushKV("ban_reason", banEntry.banReasonToString()); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -223,11 +223,9 @@ std::vector> vCommands; - for (std::map::const_iterator - mi = mapCommands.begin(); - mi != mapCommands.end(); ++mi) { + for (const auto &entry : mapCommands) { vCommands.push_back( - std::make_pair(mi->second->category + mi->first, mi->second)); + std::make_pair(entry.second->category + entry.first, entry.second)); } sort(vCommands.begin(), vCommands.end()); diff --git a/src/serialize.h b/src/serialize.h --- a/src/serialize.h +++ b/src/serialize.h @@ -734,8 +734,8 @@ template void Serialize(Stream &os, const std::map &m) { WriteCompactSize(os, m.size()); - for (const std::pair &p : m) { - Serialize(os, p); + for (const auto &entry : m) { + Serialize(os, entry); } } diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -83,9 +83,8 @@ // it. size_t ret = memusage::DynamicUsage(cacheCoins); size_t count = 0; - for (CCoinsMap::iterator it = cacheCoins.begin(); - it != cacheCoins.end(); it++) { - ret += it->second.coin.DynamicMemoryUsage(); + for (const auto &entry : cacheCoins) { + ret += entry.second.coin.DynamicMemoryUsage(); count++; } BOOST_CHECK_EQUAL(GetCacheSize(), count); @@ -189,15 +188,15 @@ // Once every 1000 iterations and at the end, verify the full cache. if (InsecureRandRange(1000) == 1 || i == NUM_SIMULATION_ITERATIONS - 1) { - for (auto it = result.begin(); it != result.end(); it++) { - bool have = stack.back()->HaveCoin(it->first); - const Coin &coin = stack.back()->AccessCoin(it->first); + for (const auto &entry : result) { + bool have = stack.back()->HaveCoin(entry.first); + const Coin &coin = stack.back()->AccessCoin(entry.first); BOOST_CHECK(have == !coin.IsSpent()); - BOOST_CHECK(coin == it->second); + BOOST_CHECK(coin == entry.second); if (coin.IsSpent()) { missed_an_entry = true; } else { - BOOST_CHECK(stack.back()->HaveCoinInCache(it->first)); + BOOST_CHECK(stack.back()->HaveCoinInCache(entry.first)); found_an_entry = true; } } @@ -435,11 +434,11 @@ // Once every 1000 iterations and at the end, verify the full cache. if (InsecureRandRange(1000) == 1 || i == NUM_SIMULATION_ITERATIONS - 1) { - for (auto it = result.begin(); it != result.end(); it++) { - bool have = stack.back()->HaveCoin(it->first); - const Coin &coin = stack.back()->AccessCoin(it->first); + for (const auto &entry : result) { + bool have = stack.back()->HaveCoin(entry.first); + const Coin &coin = stack.back()->AccessCoin(entry.first); BOOST_CHECK(have == !coin.IsSpent()); - BOOST_CHECK(coin == it->second); + BOOST_CHECK(coin == entry.second); } } diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4105,8 +4105,8 @@ void PruneOneBlockFile(const int fileNumber) { LOCK(cs_LastBlockFile); - for (const std::pair &it : mapBlockIndex) { - CBlockIndex *pindex = it.second; + for (const auto &entry : mapBlockIndex) { + CBlockIndex *pindex = entry.second; if (pindex->nFile == fileNumber) { pindex->nStatus = pindex->nStatus.withData(false).withUndo(false); pindex->nFile = 0; @@ -4816,8 +4816,8 @@ // We do this after actual disconnecting, otherwise we'll end up writing the // lack of data to disk before writing the chainstate, resulting in a // failure to continue if interrupted. - for (const std::pair &p : mapBlockIndex) { - CBlockIndex *pindexIter = p.second; + for (const auto &entry : mapBlockIndex) { + CBlockIndex *pindexIter = entry.second; if (pindexIter->IsValid(BlockValidity::TRANSACTIONS) && pindexIter->nChainTx) { setBlockIndexCandidates.insert(pindexIter); @@ -5108,8 +5108,8 @@ // Build forward-pointing map of the entire block tree. std::multimap forward; - for (const std::pair &it : mapBlockIndex) { - forward.emplace(it.second->pprev, it.second); + for (auto &entry : mapBlockIndex) { + forward.emplace(entry.second->pprev, entry.second); } assert(forward.size() == mapBlockIndex.size()); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -784,9 +784,8 @@ // multimap. TxItems txByTime; - for (std::map::iterator it = mapWallet.begin(); - it != mapWallet.end(); ++it) { - CWalletTx *wtx = &((*it).second); + for (auto &entry : mapWallet) { + CWalletTx *wtx = &entry.second; txByTime.insert( std::make_pair(wtx->nTimeReceived, TxPair(wtx, nullptr))); } @@ -2155,8 +2154,8 @@ LOCK2(cs_main, cs_wallet); Amount nTotal = Amount::zero(); - for (const std::pair &p : mapWallet) { - const CWalletTx *pcoin = &p.second; + for (const auto &entry : mapWallet) { + const CWalletTx *pcoin = &entry.second; if (pcoin->IsTrusted()) { nTotal += pcoin->GetAvailableCredit(); } @@ -2169,8 +2168,8 @@ LOCK2(cs_main, cs_wallet); Amount nTotal = Amount::zero(); - for (const std::pair &p : mapWallet) { - const CWalletTx *pcoin = &p.second; + for (const auto &entry : mapWallet) { + const CWalletTx *pcoin = &entry.second; if (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0 && pcoin->InMempool()) { nTotal += pcoin->GetAvailableCredit(); @@ -2184,8 +2183,8 @@ LOCK2(cs_main, cs_wallet); Amount nTotal = Amount::zero(); - for (const std::pair &p : mapWallet) { - const CWalletTx *pcoin = &p.second; + for (const auto &entry : mapWallet) { + const CWalletTx *pcoin = &entry.second; nTotal += pcoin->GetImmatureCredit(); } @@ -2196,8 +2195,8 @@ LOCK2(cs_main, cs_wallet); Amount nTotal = Amount::zero(); - for (const std::pair &p : mapWallet) { - const CWalletTx *pcoin = &p.second; + for (const auto &entry : mapWallet) { + const CWalletTx *pcoin = &entry.second; if (pcoin->IsTrusted()) { nTotal += pcoin->GetAvailableWatchOnlyCredit(); } @@ -2210,8 +2209,8 @@ LOCK2(cs_main, cs_wallet); Amount nTotal = Amount::zero(); - for (const std::pair &p : mapWallet) { - const CWalletTx *pcoin = &p.second; + for (const auto &entry : mapWallet) { + const CWalletTx *pcoin = &entry.second; if (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0 && pcoin->InMempool()) { nTotal += pcoin->GetAvailableWatchOnlyCredit(); @@ -2225,8 +2224,8 @@ LOCK2(cs_main, cs_wallet); Amount nTotal = Amount::zero(); - for (const std::pair &p : mapWallet) { - const CWalletTx *pcoin = &p.second; + for (const auto &entry : mapWallet) { + const CWalletTx *pcoin = &entry.second; nTotal += pcoin->GetImmatureWatchOnlyCredit(); } @@ -2304,10 +2303,9 @@ Amount nTotal = Amount::zero(); LOCK2(cs_main, cs_wallet); - for (std::map::const_iterator it = mapWallet.begin(); - it != mapWallet.end(); ++it) { - const TxId &wtxid = it->first; - const CWalletTx *pcoin = &(*it).second; + for (const auto &entry : mapWallet) { + const TxId &wtxid = entry.first; + const CWalletTx *pcoin = &entry.second; if (!CheckFinalTx(*pcoin)) { continue; @@ -2367,11 +2365,11 @@ if (coinControl && coinControl->HasSelected() && !coinControl->fAllowOtherInputs && - !coinControl->IsSelected(COutPoint((*it).first, i))) { + !coinControl->IsSelected(COutPoint(entry.first, i))) { continue; } - if (IsLockedCoin((*it).first, i)) { + if (IsLockedCoin(entry.first, i)) { continue; } @@ -4005,10 +4003,9 @@ // Find first block that affects those keys, if there are any left. std::vector vAffected; - for (std::map::const_iterator it = mapWallet.begin(); - it != mapWallet.end(); it++) { - // Iterate over all wallet transactions... - const CWalletTx &wtx = (*it).second; + for (const auto &entry : mapWallet) { + // iterate over all wallet transactions... + const CWalletTx &wtx = entry.second; BlockMap::const_iterator blit = mapBlockIndex.find(wtx.hashBlock); if (blit != mapBlockIndex.end() && chainActive.Contains(blit->second)) { // ... which are already in a block. @@ -4032,9 +4029,10 @@ } // Extract block timestamps for those keys. - for (const std::pair &p : mapKeyFirstBlock) { - // Block times can be 2h off. - mapKeyBirth[p.first] = p.second->GetBlockTime() - TIMESTAMP_WINDOW; + for (const auto &entry : mapKeyFirstBlock) { + // block times can be 2h off + mapKeyBirth[entry.first] = + entry.second->GetBlockTime() - TIMESTAMP_WINDOW; } } diff --git a/src/zmq/zmqnotificationinterface.cpp b/src/zmq/zmqnotificationinterface.cpp --- a/src/zmq/zmqnotificationinterface.cpp +++ b/src/zmq/zmqnotificationinterface.cpp @@ -40,15 +40,13 @@ factories["pubrawtx"] = CZMQAbstractNotifier::Create; - for (std::map::const_iterator i = - factories.begin(); - i != factories.end(); ++i) { - std::string arg("-zmq" + i->first); + for (const auto &entry : factories) { + std::string arg("-zmq" + entry.first); if (gArgs.IsArgSet(arg)) { - CZMQNotifierFactory factory = i->second; + CZMQNotifierFactory factory = entry.second; std::string address = gArgs.GetArg(arg, ""); CZMQAbstractNotifier *notifier = factory(); - notifier->SetType(i->first); + notifier->SetType(entry.first); notifier->SetAddress(address); notifiers.push_back(notifier); }