mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-07-15 08:35:11 +01:00
Codechange: Use ranges to get select server list position. (#13316)
Replaces a raw loop that uses array indexes.
This commit is contained in:
parent
95f8fc983b
commit
84e049e23c
@ -325,12 +325,11 @@ protected:
|
|||||||
/** Set this->list_pos to match this->server */
|
/** Set this->list_pos to match this->server */
|
||||||
void UpdateListPos()
|
void UpdateListPos()
|
||||||
{
|
{
|
||||||
this->list_pos = SLP_INVALID;
|
auto it = std::ranges::find(this->servers, this->server);
|
||||||
for (uint i = 0; i != this->servers.size(); i++) {
|
if (it == std::end(this->servers)) {
|
||||||
if (this->servers[i] == this->server) {
|
this->list_pos = SLP_INVALID;
|
||||||
this->list_pos = i;
|
} else {
|
||||||
break;
|
this->list_pos = static_cast<ServerListPosition>(std::distance(std::begin(this->servers), it));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user