From 2fa4fd196176160a5ad0a25da173ff93252b8103 Mon Sep 17 00:00:00 2001 From: Samuel Dobson Date: Tue, 23 Nov 2021 17:33:46 +1300 Subject: [PATCH] Use std::iota instead of manually pushing range --- src/bech32.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/bech32.cpp b/src/bech32.cpp index 484586cfa59..119be74b573 100644 --- a/src/bech32.cpp +++ b/src/bech32.cpp @@ -6,9 +6,10 @@ #include #include -#include -#include #include +#include +#include +#include namespace bech32 { @@ -282,13 +283,6 @@ inline unsigned char LowerCase(unsigned char c) return (c >= 'A' && c <= 'Z') ? (c - 'A') + 'a' : c; } -void push_range(int from, int to, std::vector& vec) -{ - for (int i = from; i < to; i++) { - vec.push_back(i); - } -} - /** Return indices of invalid characters in a Bech32 string. */ bool CheckCharacters(const std::string& str, std::vector& errors) { bool lower = false, upper = false; @@ -404,7 +398,8 @@ DecodeResult Decode(const std::string& str) { /** Find index of an incorrect character in a Bech32 string. */ std::string LocateErrors(const std::string& str, std::vector& error_locations) { if (str.size() > 90) { - push_range(90, str.size(), error_locations); + error_locations.resize(str.size() - 90); + std::iota(error_locations.begin(), error_locations.end(), 90); return "Bech32 string too long"; } if (!CheckCharacters(str, error_locations)){