Skip to content

Commit 58cb947

Browse files
FlamefireFlow86
authored andcommitted
Use helpers::sort consistently
1 parent 322c705 commit 58cb947

18 files changed

Lines changed: 37 additions & 30 deletions

File tree

libs/common/include/helpers/containerUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ size_t count_if(const T& container, T_Predicate&& predicate)
132132
template<class T, class T_Predicate = std::less<>>
133133
void sort(T& container, T_Predicate&& predicate = T_Predicate{})
134134
{
135+
using std::begin;
136+
using std::end;
135137
std::sort(begin(container), end(container), std::forward<T_Predicate>(predicate));
136138
}
137139

libs/libGamedata/lua/CheckedLuaTable.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: GPL-2.0-or-later
44

55
#include "CheckedLuaTable.h"
6+
#include "helpers/containerUtils.h"
67
#include "s25util/Log.h"
78
#include <boost/algorithm/string/join.hpp>
89
#include <algorithm>
@@ -22,7 +23,7 @@ void CheckedLuaTable::checkUnused()
2223
checkEnabled = false;
2324

2425
std::vector<std::string> tableKeys = table.keys<std::string>();
25-
std::sort(tableKeys.begin(), tableKeys.end());
26+
helpers::sort(tableKeys);
2627
std::vector<std::string> unusedKeys;
2728
std::set_difference(tableKeys.begin(), tableKeys.end(), accessedKeys_.begin(), accessedKeys_.end(),
2829
std::back_inserter(unusedKeys));

libs/s25main/GamePlayer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ struct ClientForWare
10221022
: bld(bld), estimate(estimate), points(points)
10231023
{}
10241024

1025-
bool operator<(const ClientForWare& b) const
1025+
bool operator<(const ClientForWare& b) const noexcept
10261026
{
10271027
// use estimate, points and object id (as tie breaker) for sorting
10281028
if(estimate != b.estimate)
@@ -1118,7 +1118,7 @@ noBaseBuilding* GamePlayer::FindClientForWare(const Ware& ware)
11181118
}
11191119

11201120
// sort our clients, highest score first
1121-
std::sort(possibleClients.begin(), possibleClients.end());
1121+
helpers::sort(possibleClients);
11221122

11231123
noBaseBuilding* lastBld = nullptr;
11241124
noBaseBuilding* bestBld = nullptr;
@@ -1903,7 +1903,7 @@ struct ShipForHarbor
19031903

19041904
ShipForHarbor(noShip* ship, uint32_t estimate) : ship(ship), estimate(estimate) {}
19051905

1906-
bool operator<(const ShipForHarbor& b) const
1906+
bool operator<(const ShipForHarbor& b) const noexcept
19071907
{
19081908
return (estimate < b.estimate) || (estimate == b.estimate && ship->GetObjId() < b.ship->GetObjId());
19091909
}
@@ -1934,7 +1934,7 @@ bool GamePlayer::OrderShip(nobHarborBuilding& hb)
19341934
}
19351935
}
19361936

1937-
std::sort(sfh.begin(), sfh.end());
1937+
helpers::sort(sfh);
19381938

19391939
noShip* best_ship = nullptr;
19401940
uint32_t best_distance = std::numeric_limits<uint32_t>::max();
@@ -2313,7 +2313,7 @@ void GamePlayer::Trade(nobBaseWarehouse* goalWh, const boost_variant2<GoodType,
23132313
const MapPoint goalFlagPos = goalWh->GetFlagPos();
23142314

23152315
std::vector<nobBaseWarehouse*> whs(buildings.GetStorehouses().begin(), buildings.GetStorehouses().end());
2316-
std::sort(whs.begin(), whs.end(), WarehouseDistanceComparator(*goalWh, world));
2316+
helpers::sort(whs, WarehouseDistanceComparator(*goalWh, world));
23172317
TradePathCache& tradePathCache = world.GetTradePathCache();
23182318
for(nobBaseWarehouse* wh : whs)
23192319
{

libs/s25main/ListDir.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: GPL-2.0-or-later
44

55
#include "ListDir.h"
6+
#include "helpers/containerUtils.h"
67
#include "s25util/strAlgos.h"
78
#include <boost/filesystem.hpp>
89
#include <algorithm>
@@ -41,6 +42,6 @@ std::vector<bfs::path> ListDir(const bfs::path& path, std::string extension, boo
4142
result.emplace_back(std::move(curPath));
4243
}
4344

44-
std::sort(result.begin(), result.end());
45+
helpers::sort(result);
4546
return result;
4647
}

libs/s25main/buildings/nobBaseMilitary.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class nobBaseMilitary : public noBuilding
5656
const nofDefender* GetDefender() const { return defender_; }
5757

5858
/// Compares according to build time (Age): Bigger objIds are "younger"
59-
bool operator<(const nobBaseMilitary& other) const { return GetObjId() > other.GetObjId(); }
59+
bool operator<(const nobBaseMilitary& other) const noexcept { return GetObjId() > other.GetObjId(); }
6060

6161
/// Meldet ein neues "Rausgeh"-Event an, falls gerade keiner rausgeht
6262
/// (damit nicht alle auf einmal rauskommen), für Lager- und Militärhäuser)

libs/s25main/controls/ctrlTable.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "ctrlScrollBar.h"
99
#include "driver/KeyEvent.h"
1010
#include "driver/MouseCoords.h"
11+
#include "helpers/containerUtils.h"
1112
#include "helpers/mathFuncs.h"
1213
#include "ogl/glFont.h"
1314
#include "s25util/StringConversion.h"
@@ -295,7 +296,7 @@ void ctrlTable::SortRows(unsigned column, const TableSortDir sortDir)
295296
const int cmpResult = Compare(a, b, sortType);
296297
return (sortDir == TableSortDir::Ascending) ? cmpResult < 0 : cmpResult > 0;
297298
};
298-
std::sort(rows_.begin(), rows_.end(), compareFunc);
299+
helpers::sort(rows_, compareFunc);
299300
}
300301

301302
/**

libs/s25main/desktops/dskOptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ void dskOptions::loadVideoModes()
743743
// Remove everything below 800x600
744744
helpers::erase_if(video_modes, [](const auto& it) { return it.width < 800 && it.height < 600; });
745745
// Sort by aspect ratio
746-
std::sort(video_modes.begin(), video_modes.end(), cmpVideoModes);
746+
helpers::sort(video_modes, cmpVideoModes);
747747
}
748748

749749
void dskOptions::Msg_ScreenResize(const ScreenResizeEvent& sr)

libs/s25main/gameTypes/HarborPos.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct HarborPos
1919

2020
Neighbor(HarborId id, unsigned distance) noexcept : id(id), distance(distance) {}
2121

22-
bool operator<(const Neighbor& two) const
22+
bool operator<(const Neighbor& two) const noexcept
2323
{
2424
return (distance < two.distance) || (distance == two.distance && id.value() < two.id.value());
2525
}

libs/s25main/languages.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "libsiedler2/ArchivItem_Text.h"
1313
#include <algorithm>
1414

15-
static bool operator<(const Language& o1, const Language& o2)
15+
static bool operator<(const Language& o1, const Language& o2) noexcept
1616
{
1717
if(o1.name < o2.name)
1818
return true;
@@ -45,7 +45,7 @@ void Languages::loadLanguages()
4545
}
4646

4747
// Sprachen sortieren
48-
std::sort(languages.begin(), languages.end());
48+
helpers::sort(languages);
4949

5050
// Systemsprache hinzufügen
5151
Language l(gettext_noop("System language"), "");

libs/s25main/mapGenerator/HeadQuarters.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ std::vector<MapPoint> FindHqPositions(const Map& map, const T_Container& area, M
6666
const auto byDistanceToOtherHqs = [&distanceToOtherHqs](MapPoint p1, MapPoint p2) {
6767
return distanceToOtherHqs[p1] > distanceToOtherHqs[p2];
6868
};
69-
std::sort(possiblePositions.begin(), possiblePositions.end(), byDistanceToOtherHqs);
69+
helpers::sort(possiblePositions, byDistanceToOtherHqs);
7070

7171
// 3. filter out points within minimum distance to existing HQs
7272
const unsigned minHqDistance = (map.size.x + map.size.y) / 16;

0 commit comments

Comments
 (0)