diff options
author | Michael Lutz <michi@icosahedron.de> | 2020-12-15 00:22:04 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2020-12-15 00:29:30 +0100 |
commit | 79240eab1ee4abb2882a40c7ac18e4915b4dc820 (patch) | |
tree | 98abb3c8ccf490efa459ed29fe7f28699c8d9928 | |
parent | cc1679e3171bf6982164c4072a773fdd687ea885 (diff) | |
download | openttd-79240eab1ee4abb2882a40c7ac18e4915b4dc820.tar.xz |
Codechange: Make use of the improved C++17 emplace_back function.
-rw-r--r-- | src/bridge_gui.cpp | 3 | ||||
-rw-r--r-- | src/core/smallmap_type.hpp | 3 | ||||
-rw-r--r-- | src/engine.cpp | 3 | ||||
-rw-r--r-- | src/fios.h | 3 | ||||
-rw-r--r-- | src/industry_gui.cpp | 12 | ||||
-rw-r--r-- | src/newgrf.cpp | 6 | ||||
-rw-r--r-- | src/newgrf_commons.cpp | 6 | ||||
-rw-r--r-- | src/saveload/afterload.cpp | 3 | ||||
-rw-r--r-- | src/saveload/engine_sl.cpp | 3 | ||||
-rw-r--r-- | src/saveload/waypoint_sl.cpp | 3 | ||||
-rw-r--r-- | src/settingsgen/settingsgen.cpp | 3 | ||||
-rw-r--r-- | src/stringfilter.cpp | 3 | ||||
-rw-r--r-- | src/tunnelbridge_cmd.cpp | 3 | ||||
-rw-r--r-- | src/viewport.cpp | 12 |
14 files changed, 22 insertions, 44 deletions
diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp index 44cc99ba3..a69ed7448 100644 --- a/src/bridge_gui.cpp +++ b/src/bridge_gui.cpp @@ -433,8 +433,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo type_check = CheckBridgeAvailability(brd_type, bridge_len); if (type_check.Succeeded()) { /* bridge is accepted, add to list */ - /*C++17: BuildBridgeData &item = */ bl->emplace_back(); - BuildBridgeData &item = bl->back(); + BuildBridgeData &item = bl->emplace_back(); item.index = brd_type; item.spec = GetBridgeSpec(brd_type); /* Add to terraforming & bulldozing costs the cost of the diff --git a/src/core/smallmap_type.hpp b/src/core/smallmap_type.hpp index 931a4848b..744f9fd26 100644 --- a/src/core/smallmap_type.hpp +++ b/src/core/smallmap_type.hpp @@ -142,8 +142,7 @@ struct SmallMap : std::vector<std::pair<T, U> > { for (uint i = 0; i < std::vector<Pair>::size(); i++) { if (key == std::vector<Pair>::operator[](i).first) return std::vector<Pair>::operator[](i).second; } - /*C++17: Pair &n = */ std::vector<Pair>::emplace_back(); - Pair &n = std::vector<Pair>::back(); + Pair &n = std::vector<Pair>::emplace_back(); n.first = key; return n.second; } diff --git a/src/engine.cpp b/src/engine.cpp index 41849b8a2..311a936ed 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -486,8 +486,7 @@ void EngineOverrideManager::ResetToDefaultMapping() this->clear(); for (VehicleType type = VEH_TRAIN; type <= VEH_AIRCRAFT; type++) { for (uint internal_id = 0; internal_id < _engine_counts[type]; internal_id++) { - /*C++17: EngineIDMapping &eid = */ this->emplace_back(); - EngineIDMapping &eid = this->back(); + EngineIDMapping &eid = this->emplace_back(); eid.type = type; eid.grfid = INVALID_GRFID; eid.internal_id = internal_id; diff --git a/src/fios.h b/src/fios.h index 6a7b6bf01..259e493b2 100644 --- a/src/fios.h +++ b/src/fios.h @@ -119,8 +119,7 @@ public: */ inline FiosItem *Append() { - /*C++17: return &*/ this->files.emplace_back(); - return &this->files.back(); + return &this->files.emplace_back(); } /** diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index e54b1b2a4..caa18c8e3 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -2625,8 +2625,7 @@ struct IndustryCargoesWindow : public Window { _displayed_industries.set(it); this->fields.clear(); - /*C++17: CargoesRow &row = */ this->fields.emplace_back(); - CargoesRow &row = this->fields.back(); + CargoesRow &row = this->fields.emplace_back(); row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS); row.columns[1].MakeEmpty(CFT_SMALL_EMPTY); row.columns[2].MakeEmpty(CFT_SMALL_EMPTY); @@ -2641,8 +2640,7 @@ struct IndustryCargoesWindow : public Window { int num_cust = CountMatchingAcceptingIndustries(central_sp->produced_cargo, lengthof(central_sp->produced_cargo)) + houses_accept; int num_indrows = max(3, max(num_supp, num_cust)); // One is needed for the 'it' industry, and 2 for the cargo labels. for (int i = 0; i < num_indrows; i++) { - /*C++17: CargoesRow &row = */ this->fields.emplace_back(); - CargoesRow &row = this->fields.back(); + CargoesRow &row = this->fields.emplace_back(); row.columns[0].MakeEmpty(CFT_EMPTY); row.columns[1].MakeCargo(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo)); row.columns[2].MakeEmpty(CFT_EMPTY); @@ -2705,8 +2703,7 @@ struct IndustryCargoesWindow : public Window { _displayed_industries.reset(); this->fields.clear(); - /*C++17: CargoesRow &row = */ this->fields.emplace_back(); - CargoesRow &row = this->fields.back(); + CargoesRow &row = this->fields.emplace_back(); row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS); row.columns[1].MakeEmpty(CFT_SMALL_EMPTY); row.columns[2].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS); @@ -2719,8 +2716,7 @@ struct IndustryCargoesWindow : public Window { int num_cust = CountMatchingAcceptingIndustries(&cid, 1) + houses_accept; int num_indrows = max(num_supp, num_cust); for (int i = 0; i < num_indrows; i++) { - /*C++17: CargoesRow &row = */ this->fields.emplace_back(); - CargoesRow &row = this->fields.back(); + CargoesRow &row = this->fields.emplace_back(); row.columns[0].MakeEmpty(CFT_EMPTY); row.columns[1].MakeCargo(&cid, 1); row.columns[2].MakeEmpty(CFT_EMPTY); diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 4abbcb3b7..21dc9ffb4 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -1916,8 +1916,7 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, Byte tmp_layout.clear(); for (;;) { /* no relative bounding box support */ - /*C++17: DrawTileSeqStruct &dtss = */ tmp_layout.emplace_back(); - DrawTileSeqStruct &dtss = tmp_layout.back(); + DrawTileSeqStruct &dtss = tmp_layout.emplace_back(); MemSetT(&dtss, 0); dtss.delta_x = buf->ReadByte(); @@ -5020,8 +5019,7 @@ static void NewSpriteGroup(ByteReader *buf) /* Loop through the var adjusts. Unfortunately we don't know how many we have * from the outset, so we shall have to keep reallocing. */ do { - /*C++17: DeterministicSpriteGroupAdjust &adjust = */ adjusts.emplace_back(); - DeterministicSpriteGroupAdjust &adjust = adjusts.back(); + DeterministicSpriteGroupAdjust &adjust = adjusts.emplace_back(); /* The first var adjust doesn't have an operation specified, so we set it to add. */ adjust.operation = adjusts.size() == 1 ? DSGA_OP_ADD : (DeterministicSpriteGroupAdjustOperation)buf->ReadByte(); diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp index 8209d675c..64eed8139 100644 --- a/src/newgrf_commons.cpp +++ b/src/newgrf_commons.cpp @@ -664,8 +664,7 @@ uint32 NewGRFSpriteLayout::PrepareLayout(uint32 orig_offset, uint32 newgrf_groun /* Create a copy of the spritelayout, so we can modify some values. * Also include the groundsprite into the sequence for easier processing. */ - /*C++17: DrawTileSeqStruct *result = &*/ result_seq.emplace_back(); - DrawTileSeqStruct *result = &result_seq.back(); + DrawTileSeqStruct *result = &result_seq.emplace_back(); result->image = ground; result->delta_x = 0; result->delta_y = 0; @@ -675,8 +674,7 @@ uint32 NewGRFSpriteLayout::PrepareLayout(uint32 orig_offset, uint32 newgrf_groun foreach_draw_tile_seq(dtss, this->seq) { result_seq.push_back(*dtss); } - result_seq.emplace_back() /*C++17: .MakeTerminator()*/; - result_seq.back().MakeTerminator(); + result_seq.emplace_back().MakeTerminator(); /* Determine the var10 values the action-1-2-3 chains needs to be resolved for, * and apply the default sprite offsets (unless disabled). */ const TileLayoutRegisters *regs = this->registers; diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 163ded73c..7d1e70212 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2924,8 +2924,7 @@ bool AfterLoadGame() cur_skip = prev_tile_skip; } - /*C++17: uint &this_skip = */ skip_frames.push_back(prev_tile_skip); - uint &this_skip = skip_frames.back(); + uint &this_skip = skip_frames.emplace_back(prev_tile_skip); /* The following 3 curves now take longer than before */ switch (u->state) { diff --git a/src/saveload/engine_sl.cpp b/src/saveload/engine_sl.cpp index 863aabff0..b0b9d02d4 100644 --- a/src/saveload/engine_sl.cpp +++ b/src/saveload/engine_sl.cpp @@ -191,8 +191,7 @@ static void Load_EIDS() _engine_mngr.clear(); while (SlIterateArray() != -1) { - /*C++17: EngineIDMapping *eid = &*/ _engine_mngr.emplace_back(); - EngineIDMapping *eid = &_engine_mngr.back(); + EngineIDMapping *eid = &_engine_mngr.emplace_back(); SlObject(eid, _engine_id_mapping_desc); } } diff --git a/src/saveload/waypoint_sl.cpp b/src/saveload/waypoint_sl.cpp index 4117a591e..663c61f6a 100644 --- a/src/saveload/waypoint_sl.cpp +++ b/src/saveload/waypoint_sl.cpp @@ -192,8 +192,7 @@ static void Load_WAYP() int index; while ((index = SlIterateArray()) != -1) { - /*C++17: OldWaypoint *wp = &*/ _old_waypoints.emplace_back(); - OldWaypoint *wp = &_old_waypoints.back(); + OldWaypoint *wp = &_old_waypoints.emplace_back(); wp->index = index; SlObject(wp, _old_waypoint_desc); diff --git a/src/settingsgen/settingsgen.cpp b/src/settingsgen/settingsgen.cpp index 764f370bd..b2a3c76f6 100644 --- a/src/settingsgen/settingsgen.cpp +++ b/src/settingsgen/settingsgen.cpp @@ -118,8 +118,7 @@ public: text += stored_size; } while (length > 0) { - /*C++17: OutputBuffer &block =*/ this->output_buffer.emplace_back(); - OutputBuffer &block = this->output_buffer.back(); + OutputBuffer &block = this->output_buffer.emplace_back(); block.Clear(); // Initialize the new block. size_t stored_size = block.Add(text, length); length -= stored_size; diff --git a/src/stringfilter.cpp b/src/stringfilter.cpp index 30876a82d..4765a880e 100644 --- a/src/stringfilter.cpp +++ b/src/stringfilter.cpp @@ -74,8 +74,7 @@ void StringFilter::SetFilterTerm(const char *str) /* Add to word */ if (word == nullptr) { - /*C++17: word = &*/ this->word_index.push_back({dest, false}); - word = &this->word_index.back(); + word = &this->word_index.emplace_back(WordState{ dest, false }); } memcpy(dest, pos, len); diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index 1a66d530f..47bb34f19 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -710,8 +710,7 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1, * Do this for all tiles (like trees), not only objects. */ ClearedObjectArea *coa = FindClearedObject(end_tile); if (coa == nullptr) { - /*C++17: coa = &*/ _cleared_object_areas.push_back({end_tile, TileArea(end_tile, 1, 1)}); - coa = &_cleared_object_areas.back(); + coa = &_cleared_object_areas.emplace_back(ClearedObjectArea{ end_tile, TileArea(end_tile, 1, 1) }); } /* Hide the tile from the terraforming command */ diff --git a/src/viewport.cpp b/src/viewport.cpp index e28a2e606..bf1f34acd 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -498,8 +498,7 @@ static void AddTileSpriteToDraw(SpriteID image, PaletteID pal, int32 x, int32 y, { assert((image & SPRITE_MASK) < MAX_SPRITES); - /*C++17: TileSpriteToDraw &ts = */ _vd.tile_sprites_to_draw.emplace_back(); - TileSpriteToDraw &ts = _vd.tile_sprites_to_draw.back(); + TileSpriteToDraw &ts = _vd.tile_sprites_to_draw.emplace_back(); ts.image = image; ts.pal = pal; ts.sub = sub; @@ -708,8 +707,7 @@ void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, return; } - /*C++17: ParentSpriteToDraw &ps = */ _vd.parent_sprites_to_draw.emplace_back(); - ParentSpriteToDraw &ps = _vd.parent_sprites_to_draw.back(); + ParentSpriteToDraw &ps = _vd.parent_sprites_to_draw.emplace_back(); ps.x = tmp_x; ps.y = tmp_y; @@ -827,8 +825,7 @@ void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool tran *_vd.last_child = (uint)_vd.child_screen_sprites_to_draw.size(); - /*C++17: ChildScreenSpriteToDraw &cs = */ _vd.child_screen_sprites_to_draw.emplace_back(); - ChildScreenSpriteToDraw &cs = _vd.child_screen_sprites_to_draw.back(); + ChildScreenSpriteToDraw &cs = _vd.child_screen_sprites_to_draw.emplace_back(); cs.image = image; cs.pal = pal; cs.sub = sub; @@ -847,8 +844,7 @@ void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool tran static void AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2, Colours colour, uint16 width) { assert(width != 0); - /*C++17: StringSpriteToDraw &ss = */ _vd.string_sprites_to_draw.emplace_back(); - StringSpriteToDraw &ss = _vd.string_sprites_to_draw.back(); + StringSpriteToDraw &ss = _vd.string_sprites_to_draw.emplace_back(); ss.string = string; ss.x = x; ss.y = y; |