Codechange: Make use of the improved C++17 emplace_back function.

pull/217/head
Michael Lutz 4 years ago
parent cc1679e317
commit 79240eab1e

@ -433,8 +433,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo
type_check = CheckBridgeAvailability(brd_type, bridge_len); type_check = CheckBridgeAvailability(brd_type, bridge_len);
if (type_check.Succeeded()) { if (type_check.Succeeded()) {
/* bridge is accepted, add to list */ /* bridge is accepted, add to list */
/*C++17: BuildBridgeData &item = */ bl->emplace_back(); BuildBridgeData &item = bl->emplace_back();
BuildBridgeData &item = bl->back();
item.index = brd_type; item.index = brd_type;
item.spec = GetBridgeSpec(brd_type); item.spec = GetBridgeSpec(brd_type);
/* Add to terraforming & bulldozing costs the cost of the /* Add to terraforming & bulldozing costs the cost of the

@ -142,8 +142,7 @@ struct SmallMap : std::vector<std::pair<T, U> > {
for (uint i = 0; i < std::vector<Pair>::size(); i++) { 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; 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>::emplace_back();
Pair &n = std::vector<Pair>::back();
n.first = key; n.first = key;
return n.second; return n.second;
} }

@ -486,8 +486,7 @@ void EngineOverrideManager::ResetToDefaultMapping()
this->clear(); this->clear();
for (VehicleType type = VEH_TRAIN; type <= VEH_AIRCRAFT; type++) { for (VehicleType type = VEH_TRAIN; type <= VEH_AIRCRAFT; type++) {
for (uint internal_id = 0; internal_id < _engine_counts[type]; internal_id++) { for (uint internal_id = 0; internal_id < _engine_counts[type]; internal_id++) {
/*C++17: EngineIDMapping &eid = */ this->emplace_back(); EngineIDMapping &eid = this->emplace_back();
EngineIDMapping &eid = this->back();
eid.type = type; eid.type = type;
eid.grfid = INVALID_GRFID; eid.grfid = INVALID_GRFID;
eid.internal_id = internal_id; eid.internal_id = internal_id;

@ -119,8 +119,7 @@ public:
*/ */
inline FiosItem *Append() inline FiosItem *Append()
{ {
/*C++17: return &*/ this->files.emplace_back(); return &this->files.emplace_back();
return &this->files.back();
} }
/** /**

@ -2625,8 +2625,7 @@ struct IndustryCargoesWindow : public Window {
_displayed_industries.set(it); _displayed_industries.set(it);
this->fields.clear(); this->fields.clear();
/*C++17: CargoesRow &row = */ this->fields.emplace_back(); CargoesRow &row = this->fields.emplace_back();
CargoesRow &row = this->fields.back();
row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS); row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
row.columns[1].MakeEmpty(CFT_SMALL_EMPTY); row.columns[1].MakeEmpty(CFT_SMALL_EMPTY);
row.columns[2].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_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. 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++) { for (int i = 0; i < num_indrows; i++) {
/*C++17: CargoesRow &row = */ this->fields.emplace_back(); CargoesRow &row = this->fields.emplace_back();
CargoesRow &row = this->fields.back();
row.columns[0].MakeEmpty(CFT_EMPTY); row.columns[0].MakeEmpty(CFT_EMPTY);
row.columns[1].MakeCargo(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo)); row.columns[1].MakeCargo(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo));
row.columns[2].MakeEmpty(CFT_EMPTY); row.columns[2].MakeEmpty(CFT_EMPTY);
@ -2705,8 +2703,7 @@ struct IndustryCargoesWindow : public Window {
_displayed_industries.reset(); _displayed_industries.reset();
this->fields.clear(); this->fields.clear();
/*C++17: CargoesRow &row = */ this->fields.emplace_back(); CargoesRow &row = this->fields.emplace_back();
CargoesRow &row = this->fields.back();
row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS); row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
row.columns[1].MakeEmpty(CFT_SMALL_EMPTY); row.columns[1].MakeEmpty(CFT_SMALL_EMPTY);
row.columns[2].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS); 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_cust = CountMatchingAcceptingIndustries(&cid, 1) + houses_accept;
int num_indrows = max(num_supp, num_cust); int num_indrows = max(num_supp, num_cust);
for (int i = 0; i < num_indrows; i++) { for (int i = 0; i < num_indrows; i++) {
/*C++17: CargoesRow &row = */ this->fields.emplace_back(); CargoesRow &row = this->fields.emplace_back();
CargoesRow &row = this->fields.back();
row.columns[0].MakeEmpty(CFT_EMPTY); row.columns[0].MakeEmpty(CFT_EMPTY);
row.columns[1].MakeCargo(&cid, 1); row.columns[1].MakeCargo(&cid, 1);
row.columns[2].MakeEmpty(CFT_EMPTY); row.columns[2].MakeEmpty(CFT_EMPTY);

@ -1916,8 +1916,7 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, Byte
tmp_layout.clear(); tmp_layout.clear();
for (;;) { for (;;) {
/* no relative bounding box support */ /* no relative bounding box support */
/*C++17: DrawTileSeqStruct &dtss = */ tmp_layout.emplace_back(); DrawTileSeqStruct &dtss = tmp_layout.emplace_back();
DrawTileSeqStruct &dtss = tmp_layout.back();
MemSetT(&dtss, 0); MemSetT(&dtss, 0);
dtss.delta_x = buf->ReadByte(); 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 /* Loop through the var adjusts. Unfortunately we don't know how many we have
* from the outset, so we shall have to keep reallocing. */ * from the outset, so we shall have to keep reallocing. */
do { do {
/*C++17: DeterministicSpriteGroupAdjust &adjust = */ adjusts.emplace_back(); DeterministicSpriteGroupAdjust &adjust = adjusts.emplace_back();
DeterministicSpriteGroupAdjust &adjust = adjusts.back();
/* The first var adjust doesn't have an operation specified, so we set it to add. */ /* 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(); adjust.operation = adjusts.size() == 1 ? DSGA_OP_ADD : (DeterministicSpriteGroupAdjustOperation)buf->ReadByte();

@ -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. /* Create a copy of the spritelayout, so we can modify some values.
* Also include the groundsprite into the sequence for easier processing. */ * Also include the groundsprite into the sequence for easier processing. */
/*C++17: DrawTileSeqStruct *result = &*/ result_seq.emplace_back(); DrawTileSeqStruct *result = &result_seq.emplace_back();
DrawTileSeqStruct *result = &result_seq.back();
result->image = ground; result->image = ground;
result->delta_x = 0; result->delta_x = 0;
result->delta_y = 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) { foreach_draw_tile_seq(dtss, this->seq) {
result_seq.push_back(*dtss); result_seq.push_back(*dtss);
} }
result_seq.emplace_back() /*C++17: .MakeTerminator()*/; result_seq.emplace_back().MakeTerminator();
result_seq.back().MakeTerminator();
/* Determine the var10 values the action-1-2-3 chains needs to be resolved for, /* Determine the var10 values the action-1-2-3 chains needs to be resolved for,
* and apply the default sprite offsets (unless disabled). */ * and apply the default sprite offsets (unless disabled). */
const TileLayoutRegisters *regs = this->registers; const TileLayoutRegisters *regs = this->registers;

@ -2924,8 +2924,7 @@ bool AfterLoadGame()
cur_skip = prev_tile_skip; cur_skip = prev_tile_skip;
} }
/*C++17: uint &this_skip = */ skip_frames.push_back(prev_tile_skip); uint &this_skip = skip_frames.emplace_back(prev_tile_skip);
uint &this_skip = skip_frames.back();
/* The following 3 curves now take longer than before */ /* The following 3 curves now take longer than before */
switch (u->state) { switch (u->state) {

@ -191,8 +191,7 @@ static void Load_EIDS()
_engine_mngr.clear(); _engine_mngr.clear();
while (SlIterateArray() != -1) { while (SlIterateArray() != -1) {
/*C++17: EngineIDMapping *eid = &*/ _engine_mngr.emplace_back(); EngineIDMapping *eid = &_engine_mngr.emplace_back();
EngineIDMapping *eid = &_engine_mngr.back();
SlObject(eid, _engine_id_mapping_desc); SlObject(eid, _engine_id_mapping_desc);
} }
} }

@ -192,8 +192,7 @@ static void Load_WAYP()
int index; int index;
while ((index = SlIterateArray()) != -1) { while ((index = SlIterateArray()) != -1) {
/*C++17: OldWaypoint *wp = &*/ _old_waypoints.emplace_back(); OldWaypoint *wp = &_old_waypoints.emplace_back();
OldWaypoint *wp = &_old_waypoints.back();
wp->index = index; wp->index = index;
SlObject(wp, _old_waypoint_desc); SlObject(wp, _old_waypoint_desc);

@ -118,8 +118,7 @@ public:
text += stored_size; text += stored_size;
} }
while (length > 0) { while (length > 0) {
/*C++17: OutputBuffer &block =*/ this->output_buffer.emplace_back(); OutputBuffer &block = this->output_buffer.emplace_back();
OutputBuffer &block = this->output_buffer.back();
block.Clear(); // Initialize the new block. block.Clear(); // Initialize the new block.
size_t stored_size = block.Add(text, length); size_t stored_size = block.Add(text, length);
length -= stored_size; length -= stored_size;

@ -74,8 +74,7 @@ void StringFilter::SetFilterTerm(const char *str)
/* Add to word */ /* Add to word */
if (word == nullptr) { if (word == nullptr) {
/*C++17: word = &*/ this->word_index.push_back({dest, false}); word = &this->word_index.emplace_back(WordState{ dest, false });
word = &this->word_index.back();
} }
memcpy(dest, pos, len); memcpy(dest, pos, len);

@ -710,8 +710,7 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1,
* Do this for all tiles (like trees), not only objects. */ * Do this for all tiles (like trees), not only objects. */
ClearedObjectArea *coa = FindClearedObject(end_tile); ClearedObjectArea *coa = FindClearedObject(end_tile);
if (coa == nullptr) { if (coa == nullptr) {
/*C++17: coa = &*/ _cleared_object_areas.push_back({end_tile, TileArea(end_tile, 1, 1)}); coa = &_cleared_object_areas.emplace_back(ClearedObjectArea{ end_tile, TileArea(end_tile, 1, 1) });
coa = &_cleared_object_areas.back();
} }
/* Hide the tile from the terraforming command */ /* Hide the tile from the terraforming command */

@ -498,8 +498,7 @@ static void AddTileSpriteToDraw(SpriteID image, PaletteID pal, int32 x, int32 y,
{ {
assert((image & SPRITE_MASK) < MAX_SPRITES); assert((image & SPRITE_MASK) < MAX_SPRITES);
/*C++17: TileSpriteToDraw &ts = */ _vd.tile_sprites_to_draw.emplace_back(); TileSpriteToDraw &ts = _vd.tile_sprites_to_draw.emplace_back();
TileSpriteToDraw &ts = _vd.tile_sprites_to_draw.back();
ts.image = image; ts.image = image;
ts.pal = pal; ts.pal = pal;
ts.sub = sub; ts.sub = sub;
@ -708,8 +707,7 @@ void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w,
return; return;
} }
/*C++17: ParentSpriteToDraw &ps = */ _vd.parent_sprites_to_draw.emplace_back(); ParentSpriteToDraw &ps = _vd.parent_sprites_to_draw.emplace_back();
ParentSpriteToDraw &ps = _vd.parent_sprites_to_draw.back();
ps.x = tmp_x; ps.x = tmp_x;
ps.y = tmp_y; 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(); *_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.emplace_back();
ChildScreenSpriteToDraw &cs = _vd.child_screen_sprites_to_draw.back();
cs.image = image; cs.image = image;
cs.pal = pal; cs.pal = pal;
cs.sub = sub; 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) static void AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2, Colours colour, uint16 width)
{ {
assert(width != 0); assert(width != 0);
/*C++17: StringSpriteToDraw &ss = */ _vd.string_sprites_to_draw.emplace_back(); StringSpriteToDraw &ss = _vd.string_sprites_to_draw.emplace_back();
StringSpriteToDraw &ss = _vd.string_sprites_to_draw.back();
ss.string = string; ss.string = string;
ss.x = x; ss.x = x;
ss.y = y; ss.y = y;

Loading…
Cancel
Save