aboutsummaryrefslogtreecommitdiff
path: root/src/utilstrencodings.h
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2017-11-22 17:04:48 -0800
committerPieter Wuille <pieter.wuille@gmail.com>2018-03-06 20:28:08 -0800
commit3296a3bb7fc0a6c47b60c79e968dbf8175d6b716 (patch)
treeb62ed5ee923c4c61e8023a91674f8a6e7ab70034 /src/utilstrencodings.h
parentb225010a808d475cbb53aeed484295f8dc8751c4 (diff)
Generalize ConvertBits
Diffstat (limited to 'src/utilstrencodings.h')
-rw-r--r--src/utilstrencodings.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/utilstrencodings.h b/src/utilstrencodings.h
index 994e6abbad..1c9cca90b2 100644
--- a/src/utilstrencodings.h
+++ b/src/utilstrencodings.h
@@ -151,7 +151,7 @@ bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out);
/** Convert from one power-of-2 number base to another. */
template<int frombits, int tobits, bool pad, typename O, typename I>
-bool ConvertBits(O& out, I it, I end) {
+bool ConvertBits(const O& outfn, I it, I end) {
size_t acc = 0;
size_t bits = 0;
constexpr size_t maxv = (1 << tobits) - 1;
@@ -161,12 +161,12 @@ bool ConvertBits(O& out, I it, I end) {
bits += frombits;
while (bits >= tobits) {
bits -= tobits;
- out.push_back((acc >> bits) & maxv);
+ outfn((acc >> bits) & maxv);
}
++it;
}
if (pad) {
- if (bits) out.push_back((acc << (tobits - bits)) & maxv);
+ if (bits) outfn((acc << (tobits - bits)) & maxv);
} else if (bits >= frombits || ((acc << (tobits - bits)) & maxv)) {
return false;
}