From 84e049e23c53867ef5d5013caa9de79e9a0f9c84 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Tue, 14 Jan 2025 19:16:46 +0000 Subject: [PATCH] Codechange: Use ranges to get select server list position. (#13316) Replaces a raw loop that uses array indexes. --- src/network/network_gui.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 62e8854b44..2916cc78a5 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -325,12 +325,11 @@ protected: /** Set this->list_pos to match this->server */ void UpdateListPos() { - this->list_pos = SLP_INVALID; - for (uint i = 0; i != this->servers.size(); i++) { - if (this->servers[i] == this->server) { - this->list_pos = i; - break; - } + auto it = std::ranges::find(this->servers, this->server); + if (it == std::end(this->servers)) { + this->list_pos = SLP_INVALID; + } else { + this->list_pos = static_cast(std::distance(std::begin(this->servers), it)); } }