diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 43790e9ac4..8aa26f1805 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -556,7 +556,7 @@ public: peer.is_outbound ? "out" : "in", ConnectionTypeForNetinfo(peer.conn_type), peer.network, - peer.transport_protocol_type.rfind('v', 0) == 0 ? peer.transport_protocol_type[1] : ' ', + peer.transport_protocol_type.starts_with('v') == 0 ? peer.transport_protocol_type[1] : ' ', PingTimeToString(peer.min_ping), PingTimeToString(peer.ping), peer.last_send ? ToString(time_now - peer.last_send) : "", diff --git a/src/net.cpp b/src/net.cpp index 9bfb813178..4732ccf18b 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1120,16 +1120,9 @@ constexpr std::array V2ShortIDs() { static_assert(std::size(V2_DASH_IDS) <= 128); std::array ret{}; - for (size_t idx{0}; idx < std::size(ret); idx++) { - if (idx < 128 && idx < std::size(V2_BITCOIN_IDS)) { - ret[idx] = V2_BITCOIN_IDS[idx]; - } else if (idx >= 128 && idx - 128 < std::size(V2_DASH_IDS)) { - ret[idx] = V2_DASH_IDS[idx - 128]; - } else { - ret[idx] = ""; - } - } - + std::fill(ret.begin(), ret.end(), ""); + std::copy(V2_BITCOIN_IDS.begin(), V2_BITCOIN_IDS.end(), ret.begin()); + std::copy(V2_DASH_IDS.begin(), V2_DASH_IDS.end(), ret.begin() + 128); return ret; } diff --git a/src/test/fuzz/rpc.cpp b/src/test/fuzz/rpc.cpp index 435ebc1b91..fe65a71736 100644 --- a/src/test/fuzz/rpc.cpp +++ b/src/test/fuzz/rpc.cpp @@ -357,9 +357,7 @@ FUZZ_TARGET_INIT(rpc, initialize_rpc) rpc_testing_setup->CallRPC(rpc_command, arguments); } catch (const UniValue& json_rpc_error) { const std::string error_msg{find_value(json_rpc_error, "message").get_str()}; - // Once c++20 is allowed, starts_with can be used. - // if (error_msg.starts_with("Internal bug detected")) { - if (0 == error_msg.rfind("Internal bug detected", 0)) { + if (error_msg.starts_with("Internal bug detected")) { // Only allow the intentional internal bug assert(error_msg.find("trigger_internal_bug") != std::string::npos); } diff --git a/src/util/ranges.h b/src/util/ranges.h index dca6866eea..aec61de960 100644 --- a/src/util/ranges.h +++ b/src/util/ranges.h @@ -5,40 +5,20 @@ #ifndef BITCOIN_UTIL_RANGES_H #define BITCOIN_UTIL_RANGES_H -#include +#include #include -//#if __cplusplus > 201703L // C++20 compiler -//namespace ranges = std::ranges; -//#else - -#define MK_RANGE(FUN) \ -template \ -inline auto FUN(const X& ds, const Z& fn) { \ - return std::FUN(cbegin(ds), cend(ds), fn); \ -} \ -template \ -inline auto FUN(X& ds, const Z& fn) { \ - return std::FUN(begin(ds), end(ds), fn); \ -} - - namespace ranges { - MK_RANGE(all_of) - MK_RANGE(any_of) - MK_RANGE(count_if) - MK_RANGE(find_if) +using namespace std::ranges; - template - constexpr inline auto find_if_opt(const X& ds, const Z& fn) { - const auto it = ranges::find_if(ds, fn); - if (it != end(ds)) { - return std::make_optional(*it); - } - return std::optional>{}; +template +constexpr inline auto find_if_opt(const X& ds, const Z& fn) { + const auto it = std::ranges::find_if(ds, fn); + if (it != std::end(ds)) { + return std::make_optional(*it); } - + return std::optional>{}; +} } -//#endif // C++20 compiler #endif // BITCOIN_UTIL_RANGES_H diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 869af8d63b..b1f7395aba 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include