Merge #10892: Replace traditional for with ranged for in block and transaction primitives

72f0060 Replace traditional for with ranged for in primitives (Dag Robole)

Pull request description:

  Replace traditional for with ranged for in block and transaction primitives to improve readability

Tree-SHA512: c0fff603d2939149ca48b6aa72b59738a3658d49bd58b2d4ffbc85bdb774d8d5bb808fe526fe22bb9eb214de632834d373e2aab44f6019a83c0b09440cea6528
This commit is contained in:
Wladimir J. van der Laan 2017-07-27 13:59:19 +02:00 committed by Pasta
parent 07d08a8224
commit 80bc6df26f
No known key found for this signature in database
GPG Key ID: D362C9F7142766AE
2 changed files with 9 additions and 11 deletions

View File

@ -29,9 +29,8 @@ std::string CBlock::ToString() const
hashMerkleRoot.ToString(), hashMerkleRoot.ToString(),
nTime, nBits, nNonce, nTime, nBits, nNonce,
vtx.size()); vtx.size());
for (unsigned int i = 0; i < vtx.size(); i++) for (const auto& tx : vtx) {
{ s << " " << tx->ToString() << "\n";
s << " " << vtx[i]->ToString() << "\n";
} }
return s.str(); return s.str();
} }

View File

@ -99,10 +99,9 @@ CTransaction::CTransaction(CMutableTransaction &&tx) : nVersion(tx.nVersion), nT
CAmount CTransaction::GetValueOut() const CAmount CTransaction::GetValueOut() const
{ {
CAmount nValueOut = 0; CAmount nValueOut = 0;
for (std::vector<CTxOut>::const_iterator it(vout.begin()); it != vout.end(); ++it) for (const auto& tx_out : vout) {
{ nValueOut += tx_out.nValue;
nValueOut += it->nValue; if (!MoneyRange(tx_out.nValue) || !MoneyRange(nValueOut))
if (!MoneyRange(it->nValue) || !MoneyRange(nValueOut))
throw std::runtime_error(std::string(__func__) + ": value out of range"); throw std::runtime_error(std::string(__func__) + ": value out of range");
} }
return nValueOut; return nValueOut;
@ -124,9 +123,9 @@ std::string CTransaction::ToString() const
vout.size(), vout.size(),
nLockTime, nLockTime,
vExtraPayload.size()); vExtraPayload.size());
for (unsigned int i = 0; i < vin.size(); i++) for (const auto& tx_in : vin)
str += " " + vin[i].ToString() + "\n"; str += " " + tx_in.ToString() + "\n";
for (unsigned int i = 0; i < vout.size(); i++) for (const auto& tx_out : vout)
str += " " + vout[i].ToString() + "\n"; str += " " + tx_out.ToString() + "\n";
return str; return str;
} }