Skip to content

Commit 80bc6df

Browse files
laanwjPastaPastaPasta
authored andcommitted
Merge bitcoin#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
1 parent 07d08a8 commit 80bc6df

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/primitives/block.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ std::string CBlock::ToString() const
2929
hashMerkleRoot.ToString(),
3030
nTime, nBits, nNonce,
3131
vtx.size());
32-
for (unsigned int i = 0; i < vtx.size(); i++)
33-
{
34-
s << " " << vtx[i]->ToString() << "\n";
32+
for (const auto& tx : vtx) {
33+
s << " " << tx->ToString() << "\n";
3534
}
3635
return s.str();
3736
}

src/primitives/transaction.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,9 @@ CTransaction::CTransaction(CMutableTransaction &&tx) : nVersion(tx.nVersion), nT
9999
CAmount CTransaction::GetValueOut() const
100100
{
101101
CAmount nValueOut = 0;
102-
for (std::vector<CTxOut>::const_iterator it(vout.begin()); it != vout.end(); ++it)
103-
{
104-
nValueOut += it->nValue;
105-
if (!MoneyRange(it->nValue) || !MoneyRange(nValueOut))
102+
for (const auto& tx_out : vout) {
103+
nValueOut += tx_out.nValue;
104+
if (!MoneyRange(tx_out.nValue) || !MoneyRange(nValueOut))
106105
throw std::runtime_error(std::string(__func__) + ": value out of range");
107106
}
108107
return nValueOut;
@@ -124,9 +123,9 @@ std::string CTransaction::ToString() const
124123
vout.size(),
125124
nLockTime,
126125
vExtraPayload.size());
127-
for (unsigned int i = 0; i < vin.size(); i++)
128-
str += " " + vin[i].ToString() + "\n";
129-
for (unsigned int i = 0; i < vout.size(); i++)
130-
str += " " + vout[i].ToString() + "\n";
126+
for (const auto& tx_in : vin)
127+
str += " " + tx_in.ToString() + "\n";
128+
for (const auto& tx_out : vout)
129+
str += " " + tx_out.ToString() + "\n";
131130
return str;
132131
}

0 commit comments

Comments
 (0)