diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-07-27 13:59:19 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-07-27 14:00:24 +0200 |
commit | ba1bbb049b8f3ad295f36b060f775591b1fed8c1 (patch) | |
tree | 39090a3144639dacb68dfbce4b1c5f2ba8ca5076 /src | |
parent | 8a99fe053a5d9a0672556fb187c602e51d2f1076 (diff) | |
parent | 72f00608d0a130a1488dc49df1073abe01d49519 (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/primitives/block.cpp | 5 | ||||
-rw-r--r-- | src/primitives/transaction.cpp | 19 |
2 files changed, 11 insertions, 13 deletions
diff --git a/src/primitives/block.cpp b/src/primitives/block.cpp index 24be67c84f..3774ac3e4b 100644 --- a/src/primitives/block.cpp +++ b/src/primitives/block.cpp @@ -25,9 +25,8 @@ std::string CBlock::ToString() const hashMerkleRoot.ToString(), nTime, nBits, nNonce, vtx.size()); - for (unsigned int i = 0; i < vtx.size(); i++) - { - s << " " << vtx[i]->ToString() << "\n"; + for (const auto& tx : vtx) { + s << " " << tx->ToString() << "\n"; } return s.str(); } diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index f87934d586..9b6a814e1f 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -83,10 +83,9 @@ CTransaction::CTransaction(CMutableTransaction &&tx) : nVersion(tx.nVersion), vi CAmount CTransaction::GetValueOut() const { CAmount nValueOut = 0; - for (std::vector<CTxOut>::const_iterator it(vout.begin()); it != vout.end(); ++it) - { - nValueOut += it->nValue; - if (!MoneyRange(it->nValue) || !MoneyRange(nValueOut)) + for (const auto& tx_out : vout) { + nValueOut += tx_out.nValue; + if (!MoneyRange(tx_out.nValue) || !MoneyRange(nValueOut)) throw std::runtime_error(std::string(__func__) + ": value out of range"); } return nValueOut; @@ -106,11 +105,11 @@ std::string CTransaction::ToString() const vin.size(), vout.size(), nLockTime); - for (unsigned int i = 0; i < vin.size(); i++) - str += " " + vin[i].ToString() + "\n"; - for (unsigned int i = 0; i < vin.size(); i++) - str += " " + vin[i].scriptWitness.ToString() + "\n"; - for (unsigned int i = 0; i < vout.size(); i++) - str += " " + vout[i].ToString() + "\n"; + for (const auto& tx_in : vin) + str += " " + tx_in.ToString() + "\n"; + for (const auto& tx_in : vin) + str += " " + tx_in.scriptWitness.ToString() + "\n"; + for (const auto& tx_out : vout) + str += " " + tx_out.ToString() + "\n"; return str; } |