From c9276c295919bfbe5e6df213eabbe9f14a16c09c Mon Sep 17 00:00:00 2001 From: Rubidium Date: Fri, 20 Oct 2023 20:09:58 +0200 Subject: [PATCH] Codechange: replace x.size() == 0 with x.empty() --- src/3rdparty/catch2/catch.hpp | 2 +- src/ai/ai_gui.cpp | 2 +- src/ai/ai_scanner.cpp | 2 +- src/blitter/factory.hpp | 2 +- src/core/kdtree.hpp | 2 +- src/core/pool_func.cpp | 2 +- src/core/span_type.hpp | 2 +- src/driver.cpp | 2 +- src/game/game_scanner.cpp | 2 +- src/gfx.cpp | 2 +- src/gfx_layout_fallback.cpp | 4 ++-- src/gfx_layout_icu.cpp | 2 +- src/group_gui.cpp | 4 ++-- src/industry_cmd.cpp | 2 +- src/industry_gui.cpp | 2 +- src/music/dmusic.cpp | 2 +- src/music/midifile.cpp | 6 +++--- src/network/core/tcp_connect.cpp | 2 +- src/network/core/tcp_listen.h | 4 ++-- src/network/core/udp.cpp | 2 +- src/network/network.cpp | 2 +- src/network/network_content_gui.cpp | 2 +- src/newgrf.cpp | 8 ++++---- src/newgrf_gui.cpp | 2 +- src/newgrf_railtype.cpp | 4 ++-- src/newgrf_roadtype.cpp | 2 +- src/os/macosx/string_osx.cpp | 2 +- src/os/windows/string_uniscribe.cpp | 2 +- src/rail_gui.cpp | 2 +- src/road_gui.cpp | 4 ++-- src/saveload/game_sl.cpp | 2 +- src/saveload/linkgraph_sl.cpp | 2 +- src/script/squirrel.cpp | 2 +- src/settings_table.cpp | 2 +- src/station.cpp | 2 +- src/story_gui.cpp | 8 ++++---- src/stringfilter_type.h | 2 +- src/strings.cpp | 2 +- src/textfile_gui.cpp | 2 +- src/town_gui.cpp | 2 +- src/train_cmd.cpp | 2 +- src/vehicle_gui.cpp | 8 ++++---- 42 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/3rdparty/catch2/catch.hpp b/src/3rdparty/catch2/catch.hpp index 9b309bddc6..109698a5c2 100644 --- a/src/3rdparty/catch2/catch.hpp +++ b/src/3rdparty/catch2/catch.hpp @@ -5922,7 +5922,7 @@ namespace Catch { } void testCaseEnded(TestCaseStats const& testCaseStats) override { auto node = std::make_shared(testCaseStats); - assert(m_sectionStack.size() == 0); + assert(m_sectionStack.empty()); node->children.push_back(m_rootSection); m_testCases.push_back(node); m_rootSection.reset(); diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index 5afbbc45f4..1e468a9b5c 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -280,7 +280,7 @@ struct AIConfigWindow : public Window { this->SetWidgetDisabledState(WID_AIC_DECREASE_INTERVAL, GetGameSettings().difficulty.competitors_interval == MIN_COMPETITORS_INTERVAL); this->SetWidgetDisabledState(WID_AIC_INCREASE_INTERVAL, GetGameSettings().difficulty.competitors_interval == MAX_COMPETITORS_INTERVAL); this->SetWidgetDisabledState(WID_AIC_CHANGE, this->selected_slot == INVALID_COMPANY); - this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || AIConfig::GetConfig(this->selected_slot)->GetConfigList()->size() == 0); + this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || AIConfig::GetConfig(this->selected_slot)->GetConfigList()->empty()); this->SetWidgetDisabledState(WID_AIC_MOVE_UP, this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot - 1))); this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot + 1))); diff --git a/src/ai/ai_scanner.cpp b/src/ai/ai_scanner.cpp index e37f2ed6c4..1b3fdf193b 100644 --- a/src/ai/ai_scanner.cpp +++ b/src/ai/ai_scanner.cpp @@ -94,7 +94,7 @@ AIInfo *AIScannerInfo::SelectRandomAI() const AIInfo *AIScannerInfo::FindInfo(const std::string &name, int version, bool force_exact_match) { - if (this->info_list.size() == 0) return nullptr; + if (this->info_list.empty()) return nullptr; if (name.empty()) return nullptr; if (version == -1) { diff --git a/src/blitter/factory.hpp b/src/blitter/factory.hpp index 3def36d0ad..5889cca4f2 100644 --- a/src/blitter/factory.hpp +++ b/src/blitter/factory.hpp @@ -120,7 +120,7 @@ public: #else const char *default_blitter = "8bpp-optimized"; #endif - if (GetBlitters().size() == 0) return nullptr; + if (GetBlitters().empty()) return nullptr; const char *bname = name.empty() ? default_blitter : name.c_str(); for (auto &it : GetBlitters()) { diff --git a/src/core/kdtree.hpp b/src/core/kdtree.hpp index 7da2aad2b9..b84c30c33c 100644 --- a/src/core/kdtree.hpp +++ b/src/core/kdtree.hpp @@ -53,7 +53,7 @@ class Kdtree { /** Create one new node in the tree, return its index in the pool */ size_t AddNode(const T &element) { - if (this->free_list.size() == 0) { + if (this->free_list.empty()) { this->nodes.emplace_back(element); return this->nodes.size() - 1; } else { diff --git a/src/core/pool_func.cpp b/src/core/pool_func.cpp index 79ea4b21ce..e59a2de447 100644 --- a/src/core/pool_func.cpp +++ b/src/core/pool_func.cpp @@ -20,7 +20,7 @@ { PoolVector *pools = PoolBase::GetPools(); pools->erase(std::find(pools->begin(), pools->end(), this)); - if (pools->size() == 0) delete pools; + if (pools->empty()) delete pools; } /** diff --git a/src/core/span_type.hpp b/src/core/span_type.hpp index beaa0be292..626a4b7b78 100644 --- a/src/core/span_type.hpp +++ b/src/core/span_type.hpp @@ -84,7 +84,7 @@ public: constexpr size_t size() const noexcept { return static_cast( last - first ); } constexpr std::ptrdiff_t ssize() const noexcept { return static_cast( last - first ); } - constexpr bool empty() const noexcept { return size() == 0; } + constexpr bool empty() const noexcept { return this->size() == 0; } constexpr iterator begin() const noexcept { return iterator(first); } constexpr iterator end() const noexcept { return iterator(last); } diff --git a/src/driver.cpp b/src/driver.cpp index 7e31390a33..5d3f2addd1 100644 --- a/src/driver.cpp +++ b/src/driver.cpp @@ -109,7 +109,7 @@ void DriverFactoryBase::SelectDriver(const std::string &name, Driver::Type type) */ bool DriverFactoryBase::SelectDriverImpl(const std::string &name, Driver::Type type) { - if (GetDrivers().size() == 0) return false; + if (GetDrivers().empty()) return false; if (name.empty()) { /* Probe for this driver, but do not fall back to dedicated/null! */ diff --git a/src/game/game_scanner.cpp b/src/game/game_scanner.cpp index 465392e698..2707e3eade 100644 --- a/src/game/game_scanner.cpp +++ b/src/game/game_scanner.cpp @@ -35,7 +35,7 @@ void GameScannerInfo::RegisterAPI(class Squirrel *engine) GameInfo *GameScannerInfo::FindInfo(const std::string &name, int version, bool force_exact_match) { - if (this->info_list.size() == 0) return nullptr; + if (this->info_list.empty()) return nullptr; if (name.empty()) return nullptr; if (version == -1) { diff --git a/src/gfx.cpp b/src/gfx.cpp index 24329c430e..c980b838c1 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -658,7 +658,7 @@ int DrawString(int left, int right, int top, std::string_view str, TextColour co } Layouter layout(str, INT32_MAX, colour, fontsize); - if (layout.size() == 0) return 0; + if (layout.empty()) return 0; return DrawLayoutLine(*layout.front(), top, left, right, align, underline, true); } diff --git a/src/gfx_layout_fallback.cpp b/src/gfx_layout_fallback.cpp index a940fc994b..1d3c4e1f99 100644 --- a/src/gfx_layout_fallback.cpp +++ b/src/gfx_layout_fallback.cpp @@ -155,7 +155,7 @@ int FallbackParagraphLayout::FallbackLine::GetLeading() const */ int FallbackParagraphLayout::FallbackLine::GetWidth() const { - if (this->size() == 0) return 0; + if (this->empty()) return 0; /* * The last X position of a run contains is the end of that run. @@ -293,7 +293,7 @@ std::unique_ptr FallbackParagraphLayout::NextLine this->buffer++; } - if (l->size() == 0 || last_char - begin > 0) { + if (l->empty() || last_char - begin > 0) { int w = l->GetWidth(); l->emplace_back(iter->second, begin, last_char - begin, begin - this->buffer_begin, w); } diff --git a/src/gfx_layout_icu.cpp b/src/gfx_layout_icu.cpp index 981563c4d8..0996b64988 100644 --- a/src/gfx_layout_icu.cpp +++ b/src/gfx_layout_icu.cpp @@ -380,7 +380,7 @@ std::vector ItemizeStyle(std::vector &runs_current, FontMap &fon runs = ItemizeScript(buff, length, runs); runs = ItemizeStyle(runs, font_mapping); - if (runs.size() == 0) return nullptr; + if (runs.empty()) return nullptr; for (auto &run : runs) { run.Shape(buff, length); diff --git a/src/group_gui.cpp b/src/group_gui.cpp index ffd965590f..55a47efe58 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -510,13 +510,13 @@ public: this->vscroll->SetCount(this->vehgroups.size()); /* The drop down menu is out, *but* it may not be used, retract it. */ - if (this->vehicles.size() == 0 && this->IsWidgetLowered(WID_GL_MANAGE_VEHICLES_DROPDOWN)) { + if (this->vehicles.empty() && this->IsWidgetLowered(WID_GL_MANAGE_VEHICLES_DROPDOWN)) { this->RaiseWidget(WID_GL_MANAGE_VEHICLES_DROPDOWN); this->CloseChildWindows(WC_DROPDOWN_MENU); } /* Disable all lists management button when the list is empty */ - this->SetWidgetsDisabledState(this->vehicles.size() == 0 || _local_company != this->vli.company, + this->SetWidgetsDisabledState(this->vehicles.empty() || _local_company != this->vli.company, WID_GL_STOP_ALL, WID_GL_START_ALL, WID_GL_MANAGE_VEHICLES_DROPDOWN); diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 6c74ac1513..7f9f6c546d 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -2683,7 +2683,7 @@ static void CanCargoServiceIndustry(CargoID cargo, Industry *ind, bool *c_accept */ int WhoCanServiceIndustry(Industry *ind) { - if (ind->stations_near.size() == 0) return 0; // No stations found at all => nobody services + if (ind->stations_near.empty()) return 0; // No stations found at all => nobody services int result = 0; for (const Vehicle *v : Vehicle::Iterate()) { diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 52ddcedad3..4d808eecc9 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -1670,7 +1670,7 @@ public: case WID_ID_INDUSTRY_LIST: { int n = 0; Rect ir = r.Shrink(WidgetDimensions::scaled.framerect); - if (this->industries.size() == 0) { + if (this->industries.empty()) { DrawString(ir, STR_INDUSTRY_DIRECTORY_NONE); break; } diff --git a/src/music/dmusic.cpp b/src/music/dmusic.cpp index 1750aabe8c..3aae02bc14 100644 --- a/src/music/dmusic.cpp +++ b/src/music/dmusic.cpp @@ -873,7 +873,7 @@ static const char *LoadDefaultDLSFile(const char *user_dls) } /* If we couldn't load the file from the registry, try again at the default install path of the GM DLS file. */ - if (dls_file.instruments.size() == 0) { + if (dls_file.instruments.empty()) { static const wchar_t *DLS_GM_FILE = L"%windir%\\System32\\drivers\\gm.dls"; wchar_t path[MAX_PATH]; ExpandEnvironmentStrings(DLS_GM_FILE, path, lengthof(path)); diff --git a/src/music/midifile.cpp b/src/music/midifile.cpp index 1caf8c1c65..6d218096c4 100644 --- a/src/music/midifile.cpp +++ b/src/music/midifile.cpp @@ -347,7 +347,7 @@ static bool FixupMidiData(MidiFile &target) std::sort(target.tempos.begin(), target.tempos.end(), TicktimeAscending); std::sort(target.blocks.begin(), target.blocks.end(), TicktimeAscending); - if (target.tempos.size() == 0) { + if (target.tempos.empty()) { /* No tempo information, assume 120 bpm (500,000 microseconds per beat */ target.tempos.push_back(MidiFile::TempoChange(0, 500000)); } @@ -359,9 +359,9 @@ static bool FixupMidiData(MidiFile &target) uint32_t last_ticktime = 0; for (size_t i = 0; i < target.blocks.size(); i++) { MidiFile::DataBlock &block = target.blocks[i]; - if (block.data.size() == 0) { + if (block.data.empty()) { continue; - } else if (block.ticktime > last_ticktime || merged_blocks.size() == 0) { + } else if (block.ticktime > last_ticktime || merged_blocks.empty()) { merged_blocks.push_back(block); last_ticktime = block.ticktime; } else { diff --git a/src/network/core/tcp_connect.cpp b/src/network/core/tcp_connect.cpp index 446023c50f..ed424249cc 100644 --- a/src/network/core/tcp_connect.cpp +++ b/src/network/core/tcp_connect.cpp @@ -203,7 +203,7 @@ void TCPConnecter::OnResolved(addrinfo *ai) } if (_debug_net_level >= 6) { - if (this->addresses.size() == 0) { + if (this->addresses.empty()) { Debug(net, 6, "{} did not resolve", this->connection_string); } else { Debug(net, 6, "{} resolved in:", this->connection_string); diff --git a/src/network/core/tcp_listen.h b/src/network/core/tcp_listen.h index 508dc8d687..088cc7b8cd 100644 --- a/src/network/core/tcp_listen.h +++ b/src/network/core/tcp_listen.h @@ -142,7 +142,7 @@ public: */ static bool Listen(uint16_t port) { - assert(sockets.size() == 0); + assert(sockets.empty()); NetworkAddressList addresses; GetBindAddresses(&addresses, port); @@ -151,7 +151,7 @@ public: address.Listen(SOCK_STREAM, &sockets); } - if (sockets.size() == 0) { + if (sockets.empty()) { Debug(net, 0, "Could not start network: could not create listening socket"); ShowNetworkError(STR_NETWORK_ERROR_SERVER_START); return false; diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp index da7ac1221b..09652225d8 100644 --- a/src/network/core/udp.cpp +++ b/src/network/core/udp.cpp @@ -73,7 +73,7 @@ void NetworkUDPSocketHandler::CloseSocket() */ void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool all, bool broadcast) { - if (this->sockets.size() == 0) this->Listen(); + if (this->sockets.empty()) this->Listen(); for (auto &s : this->sockets) { /* Make a local copy because if we resolve it we cannot diff --git a/src/network/network.cpp b/src/network/network.cpp index af65a53542..e4fe00f5ad 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -703,7 +703,7 @@ void GetBindAddresses(NetworkAddressList *addresses, uint16_t port) } /* No address, so bind to everything. */ - if (addresses->size() == 0) { + if (addresses->empty()) { addresses->emplace_back("", port); } } diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index f7b9a9a40a..a408540914 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -899,7 +899,7 @@ public: } } - if (this->content.size() == 0) { + if (this->content.empty()) { if (this->UpdateFilterState()) { this->content.ForceRebuild(); this->InvalidateData(); diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 403b20f31e..67d2370a2d 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -1192,7 +1192,7 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop break; } - if (_cur.grffile->railtype_list.size() == 0) { + if (_cur.grffile->railtype_list.empty()) { /* Use traction type to select between normal and electrified * rail only when no translation list is in place. */ if (_gted[e->index].railtypelabel == RAILTYPE_RAIL_LABEL && engclass >= EC_ELECTRIC) _gted[e->index].railtypelabel = RAILTYPE_ELECTRIC_LABEL; @@ -5242,7 +5242,7 @@ static void NewSpriteGroup(ByteReader *buf) group->default_group = GetGroupFromGroupID(setid, type, buf->ReadWord()); group->error_group = ranges.size() > 0 ? ranges[0].group : group->default_group; /* nvar == 0 is a special case -- we turn our value into a callback result */ - group->calculated_result = ranges.size() == 0; + group->calculated_result = ranges.empty(); /* Sort ranges ascending. When ranges overlap, this may required clamping or splitting them */ std::vector bounds; @@ -5511,7 +5511,7 @@ static CargoID TranslateCargo(uint8_t feature, uint8_t ctype) if ((feature == GSF_STATIONS || feature == GSF_ROADSTOPS) && ctype == 0xFE) return CT_DEFAULT_NA; if (ctype == 0xFF) return CT_PURCHASE; - if (_cur.grffile->cargo_list.size() == 0) { + if (_cur.grffile->cargo_list.empty()) { /* No cargo table, so use bitnum values */ if (ctype >= 32) { GrfMsg(1, "TranslateCargo: Cargo bitnum {} out of range (max 31), skipping.", ctype); @@ -8855,7 +8855,7 @@ static void BuildCargoTranslationMap() for (const CargoSpec *cs : CargoSpec::Iterate()) { if (!cs->IsValid()) continue; - if (_cur.grffile->cargo_list.size() == 0) { + if (_cur.grffile->cargo_list.empty()) { /* Default translation table, so just a straight mapping to bitnum */ _cur.grffile->cargo_map[cs->Index()] = cs->bitnum; } else { diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index f1f152a015..6d3c286570 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -1578,7 +1578,7 @@ void ShowMissingContentWindow(const GRFConfig *list) ci->md5sum = HasBit(c->flags, GCF_COMPATIBLE) ? c->original_md5sum : c->ident.md5sum; cv.push_back(ci); } - ShowNetworkContentListWindow(cv.size() == 0 ? nullptr : &cv, CONTENT_TYPE_NEWGRF); + ShowNetworkContentListWindow(cv.empty() ? nullptr : &cv, CONTENT_TYPE_NEWGRF); } Listing NewGRFWindow::last_sorting = {false, 0}; diff --git a/src/newgrf_railtype.cpp b/src/newgrf_railtype.cpp index 1598a4d392..694025ef07 100644 --- a/src/newgrf_railtype.cpp +++ b/src/newgrf_railtype.cpp @@ -140,7 +140,7 @@ SpriteID GetCustomSignalSprite(const RailTypeInfo *rti, TileIndex tile, SignalTy */ RailType GetRailTypeTranslation(uint8_t railtype, const GRFFile *grffile) { - if (grffile == nullptr || grffile->railtype_list.size() == 0) { + if (grffile == nullptr || grffile->railtype_list.empty()) { /* No railtype table present. Return railtype as-is (if valid), so it works for original railtypes. */ if (railtype >= RAILTYPE_END || GetRailTypeInfo(static_cast(railtype))->label == 0) return INVALID_RAILTYPE; @@ -163,7 +163,7 @@ RailType GetRailTypeTranslation(uint8_t railtype, const GRFFile *grffile) uint8_t GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile) { /* No rail type table present, return rail type as-is */ - if (grffile == nullptr || grffile->railtype_list.size() == 0) return railtype; + if (grffile == nullptr || grffile->railtype_list.empty()) return railtype; /* Look for a matching rail type label in the table */ RailTypeLabel label = GetRailTypeInfo(railtype)->label; diff --git a/src/newgrf_roadtype.cpp b/src/newgrf_roadtype.cpp index 8e3f7ce7b5..c49850d687 100644 --- a/src/newgrf_roadtype.cpp +++ b/src/newgrf_roadtype.cpp @@ -156,7 +156,7 @@ uint8_t GetReverseRoadTypeTranslation(RoadType roadtype, const GRFFile *grffile) if (grffile == nullptr) return roadtype; const std::vector *list = RoadTypeIsRoad(roadtype) ? &grffile->roadtype_list : &grffile->tramtype_list; - if (list->size() == 0) return roadtype; + if (list->empty()) return roadtype; /* Look for a matching road type label in the table */ RoadTypeLabel label = GetRoadTypeInfo(roadtype)->label; diff --git a/src/os/macosx/string_osx.cpp b/src/os/macosx/string_osx.cpp index 99d2b4a623..d9ff5f2727 100644 --- a/src/os/macosx/string_osx.cpp +++ b/src/os/macosx/string_osx.cpp @@ -276,7 +276,7 @@ int CoreTextParagraphLayout::CoreTextLine::GetLeading() const */ int CoreTextParagraphLayout::CoreTextLine::GetWidth() const { - if (this->size() == 0) return 0; + if (this->empty()) return 0; int total_width = 0; for (const auto &run : *this) { diff --git a/src/os/windows/string_uniscribe.cpp b/src/os/windows/string_uniscribe.cpp index 8615c0db03..9ee41f0eb7 100644 --- a/src/os/windows/string_uniscribe.cpp +++ b/src/os/windows/string_uniscribe.cpp @@ -291,7 +291,7 @@ static std::vector UniscribeItemizeString(UniscribeParagraphLayoutF /* Itemize text. */ std::vector items = UniscribeItemizeString(buff, length); - if (items.size() == 0) return nullptr; + if (items.empty()) return nullptr; /* Build ranges from the items and the font map. A range is a run of text * that is part of a single item and formatted using a single font style. */ diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index a8522b4050..70e1699953 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -2384,7 +2384,7 @@ DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option) } } - if (list.size() == 0) { + if (list.empty()) { /* Empty dropdowns are not allowed */ list.push_back(std::make_unique(STR_NONE, INVALID_RAILTYPE, true)); } diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 70899caebb..1a6e98a6f9 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -1845,7 +1845,7 @@ DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement, b } } - if (list.size() == 0) { + if (list.empty()) { /* Empty dropdowns are not allowed */ list.push_back(std::make_unique(STR_NONE, INVALID_ROADTYPE, true)); } @@ -1885,7 +1885,7 @@ DropDownList GetScenRoadTypeDropDownList(RoadTramTypes rtts) list.push_back(std::move(item)); } - if (list.size() == 0) { + if (list.empty()) { /* Empty dropdowns are not allowed */ list.push_back(std::make_unique(STR_NONE, -1, true)); } diff --git a/src/saveload/game_sl.cpp b/src/saveload/game_sl.cpp index bcf3189b82..87083c6694 100644 --- a/src/saveload/game_sl.cpp +++ b/src/saveload/game_sl.cpp @@ -172,7 +172,7 @@ struct GSTRChunkHandler : ChunkHandler { } /* If there were no strings in the savegame, set GameStrings to nullptr */ - if (_current_data->raw_strings.size() == 0) { + if (_current_data->raw_strings.empty()) { delete _current_data; _current_data = nullptr; return; diff --git a/src/saveload/linkgraph_sl.cpp b/src/saveload/linkgraph_sl.cpp index 8811ef0338..9295302abd 100644 --- a/src/saveload/linkgraph_sl.cpp +++ b/src/saveload/linkgraph_sl.cpp @@ -197,7 +197,7 @@ SaveLoadTable GetLinkGraphJobDesc() static SaveLoadAddrProc * const proc = [](void *b, size_t extra) -> void * { return const_cast(static_cast(reinterpret_cast(std::addressof(static_cast(b)->settings)) + extra)); }; /* Build the SaveLoad array on first call and don't touch it later on */ - if (saveloads.size() == 0) { + if (saveloads.empty()) { GetSaveLoadFromSettingTable(_linkgraph_settings, saveloads); for (auto &sl : saveloads) { diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp index b2e62dc727..167f970817 100644 --- a/src/script/squirrel.cpp +++ b/src/script/squirrel.cpp @@ -172,7 +172,7 @@ struct ScriptAllocator { ~ScriptAllocator() { #ifdef SCRIPT_DEBUG_ALLOCATIONS - assert(this->allocations.size() == 0); + assert(this->allocations.empty()); #endif } }; diff --git a/src/settings_table.cpp b/src/settings_table.cpp index 44d8189ca1..f81bb0721e 100644 --- a/src/settings_table.cpp +++ b/src/settings_table.cpp @@ -309,7 +309,7 @@ static void DifficultyNoiseChange(int32_t) static void MaxNoAIsChange(int32_t) { if (GetGameSettings().difficulty.max_no_competitors != 0 && - AI::GetInfoList()->size() == 0 && + AI::GetInfoList()->empty() && (!_networking || _network_server)) { ShowErrorMessage(STR_WARNING_NO_SUITABLE_AI, INVALID_STRING_ID, WL_CRITICAL); } diff --git a/src/station.cpp b/src/station.cpp index 2e462d457f..99957cd2f1 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -253,7 +253,7 @@ void Station::MarkTilesDirty(bool cargo_change) const /* Don't waste time updating if there are no custom station graphics * that might change. Even if there are custom graphics, they might * not change. Unfortunately we have no way of telling. */ - if (this->speclist.size() == 0) return; + if (this->speclist.empty()) return; } for (h = 0; h < train_station.h; h++) { diff --git a/src/story_gui.cpp b/src/story_gui.cpp index bdb9a4d0f3..0fece6a52b 100644 --- a/src/story_gui.cpp +++ b/src/story_gui.cpp @@ -622,8 +622,8 @@ public: */ void UpdatePrevNextDisabledState() { - this->SetWidgetDisabledState(WID_SB_PREV_PAGE, story_pages.size() == 0 || this->IsFirstPageSelected()); - this->SetWidgetDisabledState(WID_SB_NEXT_PAGE, story_pages.size() == 0 || this->IsLastPageSelected()); + this->SetWidgetDisabledState(WID_SB_PREV_PAGE, story_pages.empty() || this->IsFirstPageSelected()); + this->SetWidgetDisabledState(WID_SB_NEXT_PAGE, story_pages.empty() || this->IsLastPageSelected()); this->SetWidgetDirty(WID_SB_PREV_PAGE); this->SetWidgetDirty(WID_SB_NEXT_PAGE); } @@ -869,7 +869,7 @@ public: this->BuildStoryPageList(); /* Was the last page removed? */ - if (this->story_pages.size() == 0) { + if (this->story_pages.empty()) { this->selected_generic_title.clear(); } @@ -884,7 +884,7 @@ public: this->SetSelectedPage(this->story_pages[0]->index); } - this->SetWidgetDisabledState(WID_SB_SEL_PAGE, this->story_pages.size() == 0); + this->SetWidgetDisabledState(WID_SB_SEL_PAGE, this->story_pages.empty()); this->SetWidgetDirty(WID_SB_SEL_PAGE); this->UpdatePrevNextDisabledState(); } else if (data >= 0 && this->selected_page_id == data) { diff --git a/src/stringfilter_type.h b/src/stringfilter_type.h index 5b24587cb5..1d3098abad 100644 --- a/src/stringfilter_type.h +++ b/src/stringfilter_type.h @@ -56,7 +56,7 @@ public: * Check whether any filter words were entered. * @return true if no words were entered. */ - bool IsEmpty() const { return this->word_index.size() == 0; } + bool IsEmpty() const { return this->word_index.empty(); } void ResetState(); void AddLine(const char *str); diff --git a/src/strings.cpp b/src/strings.cpp index 8b777a79be..0eb4393dc6 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -2044,7 +2044,7 @@ void InitializeLanguagePacks() for (Searchpath sp : _valid_searchpaths) { FillLanguageList(FioGetDirectory(sp, LANG_DIR)); } - if (_languages.size() == 0) UserError("No available language packs (invalid versions?)"); + if (_languages.empty()) UserError("No available language packs (invalid versions?)"); /* Acquire the locale of the current system */ const char *lang = GetCurrentLocale("LC_MESSAGES"); diff --git a/src/textfile_gui.cpp b/src/textfile_gui.cpp index 7b5fe6e305..eb4e27274b 100644 --- a/src/textfile_gui.cpp +++ b/src/textfile_gui.cpp @@ -122,7 +122,7 @@ uint TextfileWindow::ReflowContent() uint TextfileWindow::GetContentHeight() { - if (this->lines.size() == 0) return 0; + if (this->lines.empty()) return 0; return this->lines.back().bottom; } diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 0bcdff17d3..b73db08534 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -823,7 +823,7 @@ public: case WID_TD_LIST: { int n = 0; Rect tr = r.Shrink(WidgetDimensions::scaled.framerect); - if (this->towns.size() == 0) { // No towns available. + if (this->towns.empty()) { // No towns available. DrawString(tr, STR_TOWN_DIRECTORY_NONE); break; } diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 877e2d7e3b..47cd1af9d9 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -854,7 +854,7 @@ static void MakeTrainBackup(TrainList &list, Train *t) static void RestoreTrainBackup(TrainList &list) { /* No train, nothing to do. */ - if (list.size() == 0) return; + if (list.empty()) return; Train *prev = nullptr; /* Iterate over the list and rebuild it. */ diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 9eb855f99f..e3ade7780c 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -349,7 +349,7 @@ void BaseVehicleListWindow::SetCargoFilterArray() void BaseVehicleListWindow::FilterVehicleList() { this->vehgroups.Filter(this->cargo_filter[this->cargo_filter_criteria]); - if (this->vehicles.size() == 0) { + if (this->vehicles.empty()) { /* No vehicle passed through the filter, invalidate the previously selected vehicle */ this->vehicle_sel = INVALID_VEHICLE; } else if (this->vehicle_sel != INVALID_VEHICLE && std::find(this->vehicles.begin(), this->vehicles.end(), Vehicle::Get(this->vehicle_sel)) == this->vehicles.end()) { // previously selected engine didn't pass the filter, remove selection @@ -668,7 +668,7 @@ struct RefitWindow : public Window { if (!HasBit(cmask, cid)) continue; auto &list = this->refit_list[cid]; - bool first_vehicle = list.size() == 0; + bool first_vehicle = list.empty(); if (first_vehicle) { /* Keeping the current subtype is always an option. It also serves as the option in case of no subtypes */ list.push_back({cid, UINT8_MAX, STR_EMPTY}); @@ -1949,7 +1949,7 @@ public: this->BuildVehicleList(); this->SortVehicleList(); - if (this->vehicles.size() == 0 && this->IsWidgetLowered(WID_VL_MANAGE_VEHICLES_DROPDOWN)) { + if (this->vehicles.empty() && this->IsWidgetLowered(WID_VL_MANAGE_VEHICLES_DROPDOWN)) { this->CloseChildWindows(WC_DROPDOWN_MENU); } @@ -1963,7 +1963,7 @@ public: } if (this->owner == _local_company) { this->SetWidgetDisabledState(WID_VL_AVAILABLE_VEHICLES, this->vli.type != VL_STANDARD); - this->SetWidgetsDisabledState(this->vehicles.size() == 0, + this->SetWidgetsDisabledState(this->vehicles.empty(), WID_VL_MANAGE_VEHICLES_DROPDOWN, WID_VL_STOP_ALL, WID_VL_START_ALL);