diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index 6142901c49..126b489bae 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -258,7 +258,7 @@ struct AIConfigWindow : public Window { case WID_AIC_MOVE_UP: if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot - 1))) { - Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot - 1]); + std::swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot - 1]); this->selected_slot = CompanyID(this->selected_slot - 1); this->vscroll->ScrollTowards(this->selected_slot.base()); this->InvalidateData(); @@ -267,7 +267,7 @@ struct AIConfigWindow : public Window { case WID_AIC_MOVE_DOWN: if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot + 1))) { - Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot + 1]); + std::swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot + 1]); ++this->selected_slot; this->vscroll->ScrollTowards(this->selected_slot.base()); this->InvalidateData(); diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index 8a799e74f9..24dec67dc8 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -476,7 +476,7 @@ public: int w = as->size_x; int h = as->size_y; Direction rotation = as->layouts[_selected_airport_layout].rotation; - if (rotation == DIR_E || rotation == DIR_W) Swap(w, h); + if (rotation == DIR_E || rotation == DIR_W) std::swap(w, h); SetTileSelectSize(w, h); this->preview_sprite = GetCustomAirportSprite(as, _selected_airport_layout); diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index c8c87a51cc..91025c7d01 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -476,14 +476,14 @@ static Colours GenerateCompanyColour() /* And randomize it */ for (uint i = 0; i < 100; i++) { uint r = Random(); - Swap(colours[GB(r, 0, 4)], colours[GB(r, 4, 4)]); + std::swap(colours[GB(r, 0, 4)], colours[GB(r, 4, 4)]); } /* Bubble sort it according to the values in table 1 */ for (uint i = 0; i < COLOUR_END; i++) { for (uint j = 1; j < COLOUR_END; j++) { if (_colour_sort[colours[j - 1]] < _colour_sort[colours[j]]) { - Swap(colours[j - 1], colours[j]); + std::swap(colours[j - 1], colours[j]); } } } @@ -504,7 +504,7 @@ static Colours GenerateCompanyColour() if (similar == INVALID_COLOUR) break; for (uint i = 1; i < COLOUR_END; i++) { - if (colours[i - 1] == similar) Swap(colours[i - 1], colours[i]); + if (colours[i - 1] == similar) std::swap(colours[i - 1], colours[i]); } } } diff --git a/src/core/math_func.hpp b/src/core/math_func.hpp index 921ccfa134..7207cf3baf 100644 --- a/src/core/math_func.hpp +++ b/src/core/math_func.hpp @@ -271,19 +271,6 @@ constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) no constexpr bool IsInsideMM(const ConvertibleThroughBase auto x, const size_t min, const size_t max) noexcept { return IsInsideMM(x.base(), min, max); } -/** - * Type safe swap operation - * @param a variable to swap with b - * @param b variable to swap with a - */ -template -constexpr void Swap(T &a, T &b) -{ - T t = a; - a = b; - b = t; -} - /** * Converts a "fract" value 0..255 to "percent" value 0..100 * @param i value to convert, range 0..255 diff --git a/src/landscape.cpp b/src/landscape.cpp index 3b0d99e761..702889a922 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -834,7 +834,7 @@ static void GenerateTerrain(int type, uint flag) uint w = templ->width; uint h = templ->height; - if (DiagDirToAxis(direction) == AXIS_Y) Swap(w, h); + if (DiagDirToAxis(direction) == AXIS_Y) std::swap(w, h); const uint8_t *p = templ->data; diff --git a/src/newgrf_airport.cpp b/src/newgrf_airport.cpp index b899fc732f..d215b965bf 100644 --- a/src/newgrf_airport.cpp +++ b/src/newgrf_airport.cpp @@ -103,7 +103,7 @@ bool AirportSpec::IsWithinMapBounds(uint8_t table, TileIndex tile) const uint8_t w = this->size_x; uint8_t h = this->size_y; - if (this->layouts[table].rotation == DIR_E || this->layouts[table].rotation == DIR_W) Swap(w, h); + if (this->layouts[table].rotation == DIR_E || this->layouts[table].rotation == DIR_W) std::swap(w, h); return TileX(tile) + w < Map::SizeX() && TileY(tile) + h < Map::SizeY(); diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp index 4c8dcf8f57..c7b4cbf5ca 100644 --- a/src/newgrf_commons.cpp +++ b/src/newgrf_commons.cpp @@ -418,7 +418,7 @@ TileIndex GetNearbyTile(uint8_t parameter, TileIndex tile, bool signed_offsets, /* Swap width and height depending on axis for railway stations */ if (axis == INVALID_AXIS && HasStationTileRail(tile)) axis = GetRailStationAxis(tile); - if (axis == AXIS_Y) Swap(x, y); + if (axis == AXIS_Y) std::swap(x, y); /* Make sure we never roam outside of the map, better wrap in that case */ return Map::WrapToMap(tile + TileDiffXY(x, y)); diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index 59b9975208..546b0d8f63 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -110,8 +110,8 @@ uint32_t GetPlatformInfo(Axis axis, uint8_t tile, int platforms, int length, int uint32_t retval = 0; if (axis == AXIS_X) { - Swap(platforms, length); - Swap(x, y); + std::swap(platforms, length); + std::swap(x, y); } if (centred) { diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index c1771ba735..13b38101f6 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -208,7 +208,7 @@ static void PlaceRail_Station(TileIndex tile) } else { int w = _settings_client.gui.station_numtracks; int h = _settings_client.gui.station_platlength; - if (!_station_gui.axis) Swap(w, h); + if (!_station_gui.axis) std::swap(w, h); StationPickerSelection params = _station_gui; RailType rt = _cur_railtype; @@ -372,7 +372,7 @@ static void BuildRailClick_Remove(Window *w) if (!_settings_client.gui.station_dragdrop) { int x = _settings_client.gui.station_numtracks; int y = _settings_client.gui.station_platlength; - if (_station_gui.axis == 0) Swap(x, y); + if (_station_gui.axis == 0) std::swap(x, y); SetTileSelectSize(x, y); } else { VpSetPlaceSizingLimit(_settings_game.station.station_spread); @@ -935,7 +935,7 @@ static void HandleStationPlacement(TileIndex start, TileIndex end) uint numtracks = ta.w; uint platlength = ta.h; - if (_station_gui.axis == AXIS_X) Swap(numtracks, platlength); + if (_station_gui.axis == AXIS_X) std::swap(numtracks, platlength); StationPickerSelection params = _station_gui; RailType rt = _cur_railtype; @@ -1132,7 +1132,7 @@ public: } else { int x = _settings_client.gui.station_numtracks; int y = _settings_client.gui.station_platlength; - if (_station_gui.axis == AXIS_X) Swap(x, y); + if (_station_gui.axis == AXIS_X) std::swap(x, y); if (!_remove_button_clicked) { SetTileSelectSize(x, y); } diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index b73ff3669d..0a79efb2e9 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -1065,7 +1065,7 @@ bool AfterLoadGame() case MP_ROAD: /* Swap m3 and m4, so the track type for rail crossings is the * same as for normal rail. */ - Swap(t.m3(), t.m4()); + std::swap(t.m3(), t.m4()); break; default: break; diff --git a/src/script/api/script_rail.cpp b/src/script/api/script_rail.cpp index bfab381d05..a1edc6c510 100644 --- a/src/script/api/script_rail.cpp +++ b/src/script/api/script_rail.cpp @@ -272,7 +272,7 @@ if (!IsRailTile(tile)) return false; if (from == to || ScriptMap::DistanceManhattan(from, tile) != 1 || ScriptMap::DistanceManhattan(tile, to) != 1) return false; - if (to < from) ::Swap(from, to); + if (to < from) std::swap(from, to); if (tile - from == 1) { if (to - tile == 1) return (GetRailTracks(tile) & RAILTRACK_NE_SW) != 0; diff --git a/src/station_base.h b/src/station_base.h index 6bf19082ee..3fcdbabcf7 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -101,7 +101,7 @@ public: inline void SwapShares(FlowStat &other) { this->shares.swap(other.shares); - Swap(this->unrestricted, other.unrestricted); + std::swap(this->unrestricted, other.unrestricted); } /** diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 95d4b61e8e..ec66070e84 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -2539,7 +2539,7 @@ CommandCost CmdBuildAirport(DoCommandFlags flags, TileIndex tile, uint8_t airpor Direction rotation = as->layouts[layout].rotation; int w = as->size_x; int h = as->size_y; - if (rotation == DIR_E || rotation == DIR_W) Swap(w, h); + if (rotation == DIR_E || rotation == DIR_W) std::swap(w, h); TileArea airport_area = TileArea(tile, w, h); if (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread) { @@ -3718,7 +3718,7 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i x &= 0xF; y &= 0xF; - if (DiagDirToAxis(dir) != AXIS_X) Swap(x, y); + if (DiagDirToAxis(dir) != AXIS_X) std::swap(x, y); if (y == TILE_SIZE / 2) { if (dir != DIAGDIR_SE && dir != DIAGDIR_SW) x = TILE_SIZE - 1 - x; stop &= TILE_SIZE - 1; @@ -4822,9 +4822,9 @@ StationID FlowStat::GetVia(StationID excluded, StationID excluded2) const if (interval2 >= new_max) return StationID::Invalid(); // Only the two excluded stations in the map. new_max -= interval2; if (begin > begin2) { - Swap(begin, begin2); - Swap(end, end2); - Swap(interval, interval2); + std::swap(begin, begin2); + std::swap(end, end2); + std::swap(interval, interval2); } rand = RandomRange(new_max); SharesMap::const_iterator it3 = this->shares.upper_bound(this->unrestricted); diff --git a/src/tilearea.cpp b/src/tilearea.cpp index 974f121b6c..83705a82c1 100644 --- a/src/tilearea.cpp +++ b/src/tilearea.cpp @@ -28,8 +28,8 @@ OrthogonalTileArea::OrthogonalTileArea(TileIndex start, TileIndex end) uint ex = TileX(end); uint ey = TileY(end); - if (sx > ex) Swap(sx, ex); - if (sy > ey) Swap(sy, ey); + if (sx > ex) std::swap(sx, ex); + if (sy > ey) std::swap(sy, ey); this->tile = TileXY(sx, sy); this->w = ex - sx + 1; diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index ad2a61df98..b84cde5b5a 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1643,12 +1643,12 @@ void ReverseTrainSwapVeh(Train *v, int l, int r) a->vehstatus.Set(VehState::Hidden, b_hidden); } - Swap(a->track, b->track); - Swap(a->direction, b->direction); - Swap(a->x_pos, b->x_pos); - Swap(a->y_pos, b->y_pos); - Swap(a->tile, b->tile); - Swap(a->z_pos, b->z_pos); + std::swap(a->track, b->track); + std::swap(a->direction, b->direction); + std::swap(a->x_pos, b->x_pos); + std::swap(a->y_pos, b->y_pos); + std::swap(a->tile, b->tile); + std::swap(a->z_pos, b->z_pos); SwapTrainFlags(&a->gv_flags, &b->gv_flags); diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index 5f8fc61573..ce2199076a 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -299,7 +299,7 @@ CommandCost CmdBuildBridge(DoCommandFlags flags, TileIndex tile_end, TileIndex t return CommandCost(STR_ERROR_START_AND_END_MUST_BE_IN); } - if (tile_end < tile_start) Swap(tile_start, tile_end); + if (tile_end < tile_start) std::swap(tile_start, tile_end); uint bridge_len = GetTunnelBridgeLength(tile_start, tile_end); if (transport_type != TRANSPORT_WATER) { diff --git a/src/viewport.cpp b/src/viewport.cpp index c0f74f4c95..6a33ba29ce 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -793,7 +793,7 @@ void EndSpriteCombine() */ static bool IsInRangeInclusive(int begin, int end, int check) { - if (begin > end) Swap(begin, end); + if (begin > end) std::swap(begin, end); return begin <= check && check <= end; } @@ -2672,8 +2672,8 @@ void UpdateTileSelection() if (_thd.IsDraggingDiagonal()) { new_diagonal = true; } else { - if (x1 >= x2) Swap(x1, x2); - if (y1 >= y2) Swap(y1, y2); + if (x1 >= x2) std::swap(x1, x2); + if (y1 >= y2) std::swap(y1, y2); } _thd.new_pos.x = x1; _thd.new_pos.y = y1; @@ -2936,7 +2936,7 @@ static int CalcHeightdiff(HighLightStyle style, uint distance, TileIndex start_t uint h0, h1; // Start height and end height. if (start_tile == end_tile) return 0; - if (swap) Swap(start_tile, end_tile); + if (swap) std::swap(start_tile, end_tile); switch (style & HT_DRAG_MASK) { case HT_RECT: @@ -3007,7 +3007,7 @@ static int CalcHeightdiff(HighLightStyle style, uint distance, TileIndex start_t } } - if (swap) Swap(h0, h1); + if (swap) std::swap(h0, h1); return (int)(h1 - h0) * TILE_HEIGHT_STEP; }