diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -481,7 +481,7 @@ struct AISettingsWindow : public Window DropDownList *list = new DropDownList(); for (int i = config_item.min_value; i <= config_item.max_value; i++) { - *list->Append() = new DropDownListCharStringItem(config_item.labels->Find(i)->second, i, false); + list->push_back(new DropDownListCharStringItem(config_item.labels->Find(i)->second, i, false)); } ShowDropDownListAt(this, list, old_val, -1, wi_rect, COLOUR_ORANGE, true); diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -219,7 +219,7 @@ class BuildAirportWindow : public Picker DropDownList *list = new DropDownList(); for (uint i = 0; i < AirportClass::GetClassCount(); i++) { - *list->Append() = new DropDownListStringItem(AirportClass::Get((AirportClassID)i)->name, i, false); + list->push_back(new DropDownListStringItem(AirportClass::Get((AirportClassID)i)->name, i, false)); } return list; diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -140,7 +140,7 @@ class ReplaceVehicleWindow : public Wind if (!CheckAutoreplaceValidity(this->sel_engine[0], eid, _local_company)) continue; } - *list->Append() = eid; + list->push_back(eid); if (eid == this->sel_engine[side]) selected_engine = eid; // The selected engine is still in the list } this->sel_engine[side] = selected_engine; // update which engine we selected (the same or none, if it's not in the list anymore) @@ -468,8 +468,8 @@ public: case WID_RV_TRAIN_ENGINEWAGON_DROPDOWN: { DropDownList *list = new DropDownList(); - *list->Append() = new DropDownListStringItem(STR_REPLACE_ENGINES, 1, false); - *list->Append() = new DropDownListStringItem(STR_REPLACE_WAGONS, 0, false); + list->push_back(new DropDownListStringItem(STR_REPLACE_ENGINES, 1, false)); + list->push_back(new DropDownListStringItem(STR_REPLACE_WAGONS, 0, false)); ShowDropDownList(this, list, this->replace_engines ? 1 : 0, WID_RV_TRAIN_ENGINEWAGON_DROPDOWN); break; } diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp --- a/src/bridge_gui.cpp +++ b/src/bridge_gui.cpp @@ -416,12 +416,13 @@ void ShowBuildBridgeWindow(TileIndex sta for (BridgeType brd_type = 0; brd_type != MAX_BRIDGES; brd_type++) { if (CheckBridgeAvailability(brd_type, bridge_len).Succeeded()) { /* bridge is accepted, add to list */ - BuildBridgeData *item = bl->Append(); - item->index = brd_type; - item->spec = GetBridgeSpec(brd_type); + /*C++17: BuildBridgeData &item = */ bl->emplace_back(); + BuildBridgeData &item = bl->back(); + item.index = brd_type; + item.spec = GetBridgeSpec(brd_type); /* Add to terraforming & bulldozing costs the cost of the * bridge itself (not computed with DC_QUERY_COST) */ - item->cost = ret.GetCost() + (((int64)tot_bridgedata_len * _price[PR_BUILD_BRIDGE] * item->spec->price) >> 8) + infra_cost; + item.cost = ret.GetCost() + (((int64)tot_bridgedata_len * _price[PR_BUILD_BRIDGE] * item.spec->price) >> 8) + infra_cost; } } } diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -1246,7 +1246,7 @@ struct BuildVehicleWindow : Window { /* Filter now! So num_engines and num_wagons is valid */ if (!FilterSingleEngine(eid)) continue; - *this->eng_list.Append() = eid; + this->eng_list.push_back(eid); if (rvi->railveh_type != RAILVEH_WAGON) { num_engines++; @@ -1284,7 +1284,7 @@ struct BuildVehicleWindow : Window { EngineID eid = e->index; if (!IsEngineBuildable(eid, VEH_ROAD, _local_company)) continue; if (!HasBit(this->filter.roadtypes, HasBit(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD)) continue; - *this->eng_list.Append() = eid; + this->eng_list.push_back(eid); if (eid == this->sel_engine) sel_id = eid; } @@ -1302,7 +1302,7 @@ struct BuildVehicleWindow : Window { if (!this->show_hidden_engines && e->IsHidden(_local_company)) continue; EngineID eid = e->index; if (!IsEngineBuildable(eid, VEH_SHIP, _local_company)) continue; - *this->eng_list.Append() = eid; + this->eng_list.push_back(eid); if (eid == this->sel_engine) sel_id = eid; } @@ -1330,7 +1330,7 @@ struct BuildVehicleWindow : Window { /* First VEH_END window_numbers are fake to allow a window open for all different types at once */ if (!this->listview_mode && !CanVehicleUseStation(eid, st)) continue; - *this->eng_list.Append() = eid; + this->eng_list.push_back(eid); if (eid == this->sel_engine) sel_id = eid; } diff --git a/src/company_gui.cpp b/src/company_gui.cpp --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -606,10 +606,10 @@ private: if (default_livery != NULL) { /* Add COLOUR_END to put the colour out of range, but also allow us to show what the default is */ default_col = (primary ? default_livery->colour1 : default_livery->colour2) + COLOUR_END; - *list->Append() = new DropDownListColourItem(default_col, false); + list->push_back(new DropDownListColourItem(default_col, false)); } for (uint i = 0; i < lengthof(_colour_dropdown); i++) { - *list->Append() = new DropDownListColourItem(i, HasBit(used_colours, i)); + list->push_back(new DropDownListColourItem(i, HasBit(used_colours, i))); } byte sel = (default_livery == NULL || HasBit(livery->in_use, primary ? 0 : 1)) ? (primary ? livery->colour1 : livery->colour2) : default_col; @@ -642,8 +642,8 @@ private: { for (const Group **g = source->Begin(); g != source->End(); g++) { if ((*g)->parent != parent) continue; - *this->groups.Append() = *g; - *this->indents.Append() = indent; + this->groups.push_back(*g); + this->indents.push_back(indent); AddChildren(source, (*g)->index, indent + 1); } } @@ -662,7 +662,7 @@ private: const Group *g; FOR_ALL_GROUPS(g) { if (g->owner == owner && g->vehicle_type == vtype) { - *list.Append() = g; + list.push_back(g); } } diff --git a/src/core/pool_type.hpp b/src/core/pool_type.hpp --- a/src/core/pool_type.hpp +++ b/src/core/pool_type.hpp @@ -50,7 +50,7 @@ struct PoolBase { */ PoolBase(PoolType pt) : type(pt) { - *PoolBase::GetPools()->Append() = this; + PoolBase::GetPools()->push_back(this); } virtual ~PoolBase(); diff --git a/src/core/smallmap_type.hpp b/src/core/smallmap_type.hpp --- a/src/core/smallmap_type.hpp +++ b/src/core/smallmap_type.hpp @@ -143,9 +143,7 @@ struct SmallMap : SmallVectorContains(key)) return false; - Pair *n = this->Append(); - n->first = key; - n->second = data; + std::vector::emplace_back(key, data); return true; } @@ -160,9 +158,10 @@ struct SmallMap : SmallVector::size(); i++) { if (key == std::vector::operator[](i).first) return std::vector::operator[](i).second; } - Pair *n = this->Append(); - n->first = key; - return n->second; + /*C++17: Pair &n = */ std::vector::emplace_back(); + Pair &n = std::vector::back(); + n.first = key; + return n.second; } inline void SortByKey() diff --git a/src/core/smallvec_type.hpp b/src/core/smallvec_type.hpp --- a/src/core/smallvec_type.hpp +++ b/src/core/smallvec_type.hpp @@ -67,17 +67,6 @@ public: ~SmallVector() = default; /** - * Append an item and return it. - * @param to_add the number of items to append - * @return pointer to newly allocated item - */ - inline T *Append(uint to_add = 1) - { - std::vector::resize(std::vector::size() + to_add); - return this->End() - to_add; - } - - /** * Insert a new item at a specific position into the vector, moving all following items. * @param item Position at which the new item should be inserted * @return pointer to the new item @@ -112,7 +101,7 @@ public: inline bool Include(const T &item) { bool is_member = std::find(std::vector::begin(), std::vector::end(), item) != std::vector::end(); - if (!is_member) *this->Append() = item; + if (!is_member) std::vector::emplace_back(item); return is_member; } @@ -157,6 +146,23 @@ public: } }; +/** + * Helper function to extend a vector by more than one element + * Consider using std::back_inserter in new code + * + * @param vec A reference to the vector to be extended + * @param num The number of elements to default-construct + * + * @return Pointer to the first new element + */ +template +inline T* grow(std::vector& vec, std::size_t num) +{ + const std::size_t pos = vec.size(); + vec.resize(pos + num); + return vec.data() + pos; +} + /** * Simple vector template class, with automatic free. diff --git a/src/date_gui.cpp b/src/date_gui.cpp --- a/src/date_gui.cpp +++ b/src/date_gui.cpp @@ -75,14 +75,14 @@ struct SetDateWindow : Window { case WID_SD_DAY: for (uint i = 0; i < 31; i++) { - *list->Append() = new DropDownListStringItem(STR_DAY_NUMBER_1ST + i, i + 1, false); + list->push_back(new DropDownListStringItem(STR_DAY_NUMBER_1ST + i, i + 1, false)); } selected = this->date.day; break; case WID_SD_MONTH: for (uint i = 0; i < 12; i++) { - *list->Append() = new DropDownListStringItem(STR_MONTH_JAN + i, i, false); + list->push_back(new DropDownListStringItem(STR_MONTH_JAN + i, i, false)); } selected = this->date.month; break; @@ -91,7 +91,7 @@ struct SetDateWindow : Window { for (Year i = this->min_year; i <= this->max_year; i++) { DropDownListParamStringItem *item = new DropDownListParamStringItem(STR_JUST_INT, i, false); item->SetParam(0, i); - *list->Append() = item; + list->push_back(item); } selected = this->date.year; break; diff --git a/src/engine.cpp b/src/engine.cpp --- a/src/engine.cpp +++ b/src/engine.cpp @@ -490,11 +490,12 @@ void EngineOverrideManager::ResetToDefau this->clear(); for (VehicleType type = VEH_TRAIN; type <= VEH_AIRCRAFT; type++) { for (uint internal_id = 0; internal_id < _engine_counts[type]; internal_id++) { - EngineIDMapping *eid = this->Append(); - eid->type = type; - eid->grfid = INVALID_GRFID; - eid->internal_id = internal_id; - eid->substitute_id = internal_id; + /*C++17: EngineIDMapping &eid = */ this->emplace_back(); + EngineIDMapping &eid = this->back(); + eid.type = type; + eid.grfid = INVALID_GRFID; + eid.internal_id = internal_id; + eid.substitute_id = internal_id; } } } diff --git a/src/fios.h b/src/fios.h --- a/src/fios.h +++ b/src/fios.h @@ -120,7 +120,8 @@ public: */ inline FiosItem *Append() { - return this->files.Append(); + /*C++17: return &*/ this->files.emplace_back(); + return &this->files.back(); } /** diff --git a/src/game/game_text.cpp b/src/game/game_text.cpp --- a/src/game/game_text.cpp +++ b/src/game/game_text.cpp @@ -115,7 +115,7 @@ LanguageStrings *ReadRawLanguageStrings( while (i > 0 && (buffer[i - 1] == '\r' || buffer[i - 1] == '\n' || buffer[i - 1] == ' ')) i--; buffer[i] = '\0'; - *ret->lines.Append() = stredup(buffer, buffer + to_read - 1); + ret->lines.push_back(stredup(buffer, buffer + to_read - 1)); if (len > to_read) { to_read = 0; @@ -194,7 +194,7 @@ struct TranslationWriter : LanguageWrite char *dest = MallocT(length + 1); memcpy(dest, buffer, length); dest[length] = '\0'; - *this->strings->Append() = dest; + this->strings->push_back(dest); } }; @@ -212,7 +212,7 @@ struct StringNameWriter : HeaderWriter { void WriteStringID(const char *name, int stringid) { - if (stringid == (int)this->strings->size()) *this->strings->Append() = stredup(name); + if (stringid == (int)this->strings->size()) this->strings->push_back(stredup(name)); } void Finalise(const StringData &data) @@ -246,7 +246,7 @@ public: { if (strcmp(filename, exclude) == 0) return true; - *gs->raw_strings.Append() = ReadRawLanguageStrings(filename); + gs->raw_strings.push_back(ReadRawLanguageStrings(filename)); return true; } }; @@ -269,7 +269,7 @@ GameStrings *LoadTranslations() GameStrings *gs = new GameStrings(); try { - *gs->raw_strings.Append() = ReadRawLanguageStrings(filename); + gs->raw_strings.push_back(ReadRawLanguageStrings(filename)); /* Scan for other language files */ LanguageScanner scanner(gs, filename); @@ -324,8 +324,8 @@ void GameStrings::Compile() translation_reader.ParseFile(); if (_errors != 0) throw std::exception(); - LanguageStrings *compiled = *this->compiled_strings.Append() = new LanguageStrings((*p)->language); - TranslationWriter writer(&compiled->lines); + this->compiled_strings.push_back(new LanguageStrings((*p)->language)); + TranslationWriter writer(&this->compiled_strings.back()->lines); writer.WriteLang(data); } } diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -289,7 +289,7 @@ static DropDownList *BuildMapsizeDropDow for (uint i = MIN_MAP_SIZE_BITS; i <= MAX_MAP_SIZE_BITS; i++) { DropDownListParamStringItem *item = new DropDownListParamStringItem(STR_JUST_INT, i, false); item->SetParam(0, 1LL << i); - *list->Append() = item; + list->push_back(item); } return list; diff --git a/src/gfx_layout.cpp b/src/gfx_layout.cpp --- a/src/gfx_layout.cpp +++ b/src/gfx_layout.cpp @@ -150,7 +150,7 @@ public: ICULine(icu::ParagraphLayout::Line *l) : l(l) { for (int i = 0; i < l->countRuns(); i++) { - *this->Append() = new ICUVisualRun(l->getVisualRun(i)); + this->push_back(new ICUVisualRun(l->getVisualRun(i))); } } ~ICULine() { delete l; } @@ -498,7 +498,7 @@ const ParagraphLayouter::Line *FallbackP if (*this->buffer == '\0') { /* Only a newline. */ this->buffer = NULL; - *l->Append() = new FallbackVisualRun(this->runs.Begin()->second, this->buffer, 0, 0); + l->push_back(new FallbackVisualRun(this->runs.Begin()->second, this->buffer, 0, 0)); return l; } @@ -527,7 +527,7 @@ const ParagraphLayouter::Line *FallbackP if (this->buffer == next_run) { int w = l->GetWidth(); - *l->Append() = new FallbackVisualRun(iter->second, begin, this->buffer - begin, w); + l->push_back(new FallbackVisualRun(iter->second, begin, this->buffer - begin, w)); iter++; assert(iter != this->runs.End()); @@ -574,7 +574,7 @@ const ParagraphLayouter::Line *FallbackP if (l->size() == 0 || last_char - begin != 0) { int w = l->GetWidth(); - *l->Append() = new FallbackVisualRun(iter->second, begin, last_char - begin, w); + l->push_back(new FallbackVisualRun(iter->second, begin, last_char - begin, w)); } return l; } @@ -720,7 +720,7 @@ Layouter::Layouter(const char *str, int /* Copy all lines into a local cache so we can reuse them later on more easily. */ const ParagraphLayouter::Line *l; while ((l = line.layout->NextLine(maxw)) != NULL) { - *this->Append() = l; + this->push_back(l); } } while (c != '\0'); @@ -834,7 +834,7 @@ Font *Layouter::GetFont(FontSize size, T if (it != fonts[size].End()) return it->second; Font *f = new Font(size, colour); - *fonts[size].Append() = FontColourMap::Pair(colour, f); + fonts[size].emplace_back(colour, f); return f; } diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -1140,7 +1140,7 @@ private: const Company *c; FOR_ALL_COMPANIES(c) { - *this->companies.Append() = c; + this->companies.push_back(c); } this->companies.shrink_to_fit(); diff --git a/src/group_gui.cpp b/src/group_gui.cpp --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -129,8 +129,8 @@ private: { for (const Group **g = source->Begin(); g != source->End(); g++) { if ((*g)->parent != parent) continue; - *this->groups.Append() = *g; - *this->indents.Append() = indent; + this->groups.push_back(*g); + this->indents.push_back(indent); AddChildren(source, (*g)->index, indent + 1); } } @@ -175,7 +175,7 @@ private: const Group *g; FOR_ALL_GROUPS(g) { if (g->owner == owner && g->vehicle_type == this->vli.vtype) { - *list.Append() = g; + list.push_back(g); } } diff --git a/src/hotkeys.cpp b/src/hotkeys.cpp --- a/src/hotkeys.cpp +++ b/src/hotkeys.cpp @@ -255,7 +255,7 @@ HotkeyList::HotkeyList(const char *ini_g global_hotkey_handler(global_hotkey_handler), ini_group(ini_group), items(items) { if (_hotkey_lists == NULL) _hotkey_lists = new SmallVector(); - *_hotkey_lists->Append() = this; + _hotkey_lists->push_back(this); } HotkeyList::~HotkeyList() diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -1206,7 +1206,7 @@ protected: const Industry *i; FOR_ALL_INDUSTRIES(i) { - *this->industries.Append() = i; + this->industries.push_back(i); } this->industries.shrink_to_fit(); @@ -2415,12 +2415,13 @@ struct IndustryCargoesWindow : public Wi _displayed_industries.set(it); this->fields.clear(); - CargoesRow *row = this->fields.Append(); - row->columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS); - row->columns[1].MakeEmpty(CFT_SMALL_EMPTY); - row->columns[2].MakeEmpty(CFT_SMALL_EMPTY); - row->columns[3].MakeEmpty(CFT_SMALL_EMPTY); - row->columns[4].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS); + /*C++17: CargoesRow &row = */ this->fields.emplace_back(); + CargoesRow &row = this->fields.back(); + row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS); + row.columns[1].MakeEmpty(CFT_SMALL_EMPTY); + row.columns[2].MakeEmpty(CFT_SMALL_EMPTY); + row.columns[3].MakeEmpty(CFT_SMALL_EMPTY); + row.columns[4].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS); const IndustrySpec *central_sp = GetIndustrySpec(it); bool houses_supply = HousesCanSupply(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo)); @@ -2430,12 +2431,13 @@ struct IndustryCargoesWindow : public Wi 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++) { - CargoesRow *row = this->fields.Append(); - 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); - row->columns[3].MakeCargo(central_sp->produced_cargo, lengthof(central_sp->produced_cargo)); - row->columns[4].MakeEmpty(CFT_EMPTY); + /*C++17: CargoesRow &row = */ this->fields.emplace_back(); + CargoesRow &row = this->fields.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); + row.columns[3].MakeCargo(central_sp->produced_cargo, lengthof(central_sp->produced_cargo)); + row.columns[4].MakeEmpty(CFT_EMPTY); } /* Add central industry. */ int central_row = 1 + num_indrows / 2; @@ -2493,12 +2495,13 @@ struct IndustryCargoesWindow : public Wi _displayed_industries.reset(); this->fields.clear(); - CargoesRow *row = this->fields.Append(); - row->columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS); - row->columns[1].MakeEmpty(CFT_SMALL_EMPTY); - row->columns[2].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS); - row->columns[3].MakeEmpty(CFT_SMALL_EMPTY); - row->columns[4].MakeEmpty(CFT_SMALL_EMPTY); + /*C++17: CargoesRow &row = */ this->fields.emplace_back(); + CargoesRow &row = this->fields.back(); + row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS); + row.columns[1].MakeEmpty(CFT_SMALL_EMPTY); + row.columns[2].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS); + row.columns[3].MakeEmpty(CFT_SMALL_EMPTY); + row.columns[4].MakeEmpty(CFT_SMALL_EMPTY); bool houses_supply = HousesCanSupply(&cid, 1); bool houses_accept = HousesCanAccept(&cid, 1); @@ -2506,12 +2509,13 @@ struct IndustryCargoesWindow : public Wi int num_cust = CountMatchingAcceptingIndustries(&cid, 1) + houses_accept; int num_indrows = max(num_supp, num_cust); for (int i = 0; i < num_indrows; i++) { - CargoesRow *row = this->fields.Append(); - row->columns[0].MakeEmpty(CFT_EMPTY); - row->columns[1].MakeCargo(&cid, 1); - row->columns[2].MakeEmpty(CFT_EMPTY); - row->columns[3].MakeEmpty(CFT_EMPTY); - row->columns[4].MakeEmpty(CFT_EMPTY); + /*C++17: CargoesRow &row = */ this->fields.emplace_back(); + CargoesRow &row = this->fields.back(); + row.columns[0].MakeEmpty(CFT_EMPTY); + row.columns[1].MakeCargo(&cid, 1); + row.columns[2].MakeEmpty(CFT_EMPTY); + row.columns[3].MakeEmpty(CFT_EMPTY); + row.columns[4].MakeEmpty(CFT_EMPTY); } this->fields[num_indrows].MakeCargoLabel(0, false); // Add cargo labels at the left bottom. @@ -2708,7 +2712,7 @@ struct IndustryCargoesWindow : public Wi DropDownList *lst = new DropDownList; const CargoSpec *cs; FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) { - *lst->Append() = new DropDownListStringItem(cs->name, cs->Index(), false); + lst->push_back(new DropDownListStringItem(cs->name, cs->Index(), false)); } if (lst->size() == 0) { delete lst; @@ -2725,7 +2729,7 @@ struct IndustryCargoesWindow : public Wi IndustryType ind = _sorted_industry_types[i]; const IndustrySpec *indsp = GetIndustrySpec(ind); if (!indsp->enabled) continue; - *lst->Append() = new DropDownListStringItem(indsp->name, ind, false); + lst->push_back(new DropDownListStringItem(indsp->name, ind, false)); } if (lst->size() == 0) { delete lst; diff --git a/src/linkgraph/linkgraph.cpp b/src/linkgraph/linkgraph.cpp --- a/src/linkgraph/linkgraph.cpp +++ b/src/linkgraph/linkgraph.cpp @@ -159,7 +159,7 @@ NodeID LinkGraph::AddNode(const Station const GoodsEntry &good = st->goods[this->cargo]; NodeID new_node = this->Size(); - this->nodes.Append(); + this->nodes.emplace_back(); /* Avoid reducing the height of the matrix as that is expensive and we * most likely will increase it again later which is again expensive. */ this->edges.Resize(new_node + 1U, diff --git a/src/music/midifile.cpp b/src/music/midifile.cpp --- a/src/music/midifile.cpp +++ b/src/music/midifile.cpp @@ -21,7 +21,6 @@ #include "../console_func.h" #include "../console_internal.h" - /* SMF reader based on description at: http://www.somascape.org/midi/tech/mfile.html */ @@ -217,7 +216,7 @@ static bool ReadTrackChunk(FILE *file, M case MIDIST_CONTROLLER: case MIDIST_PITCHBEND: /* 3 byte messages */ - data = block->data.Append(3); + data = grow(block->data, 3); data[0] = status; if (!chunk.ReadBuffer(&data[1], 2)) { return false; @@ -226,7 +225,7 @@ static bool ReadTrackChunk(FILE *file, M case MIDIST_PROGCHG: case MIDIST_CHANPRESS: /* 2 byte messages */ - data = block->data.Append(2); + data = grow(block->data, 2); data[0] = status; if (!chunk.ReadByte(data[1])) { return false; @@ -267,7 +266,7 @@ static bool ReadTrackChunk(FILE *file, M if (!chunk.ReadVariableLength(length)) { return false; } - byte *data = block->data.Append(length + 1); + byte *data = grow(block->data, length + 1); data[0] = 0xF0; if (!chunk.ReadBuffer(data + 1, length)) { return false; @@ -275,7 +274,7 @@ static bool ReadTrackChunk(FILE *file, M if (data[length] != 0xF7) { /* Engage Casio weirdo mode - convert to normal sysex */ running_sysex = true; - *block->data.Append() = 0xF7; + block->data.push_back(0xF7); } else { running_sysex = false; } @@ -285,7 +284,7 @@ static bool ReadTrackChunk(FILE *file, M if (!chunk.ReadVariableLength(length)) { return false; } - byte *data = block->data.Append(length); + byte *data = grow(block->data, length); if (!chunk.ReadBuffer(data, length)) { return false; } @@ -336,7 +335,7 @@ static bool FixupMidiData(MidiFile &targ merged_blocks.push_back(block); last_ticktime = block.ticktime; } else { - byte *datadest = merged_blocks.back().data.Append(block.data.size()); + byte *datadest = grow(merged_blocks.back().data, block.data.size()); memcpy(datadest, block.data.Begin(), block.data.size()); } } @@ -508,14 +507,14 @@ struct MpsMachine { static void AddMidiData(MidiFile::DataBlock &block, byte b1, byte b2) { - *block.data.Append() = b1; - *block.data.Append() = b2; + block.data.push_back(b1); + block.data.push_back(b2); } static void AddMidiData(MidiFile::DataBlock &block, byte b1, byte b2, byte b3) { - *block.data.Append() = b1; - *block.data.Append() = b2; - *block.data.Append() = b3; + block.data.push_back(b1); + block.data.push_back(b2); + block.data.push_back(b3); } /** diff --git a/src/network/core/host.cpp b/src/network/core/host.cpp --- a/src/network/core/host.cpp +++ b/src/network/core/host.cpp @@ -100,7 +100,7 @@ static void NetworkFindBroadcastIPsInter if (ifa->ifa_broadaddr->sa_family != AF_INET) continue; NetworkAddress addr(ifa->ifa_broadaddr, sizeof(sockaddr)); - if (std::none_of(broadcast->begin(), broadcast->end(), [&addr](NetworkAddress const& elem) -> bool { return elem == addr; })) *broadcast->Append() = addr; + if (std::none_of(broadcast->begin(), broadcast->end(), [&addr](NetworkAddress const& elem) -> bool { return elem == addr; })) broadcast->push_back(addr); } freeifaddrs(ifap); } diff --git a/src/network/core/tcp_connect.cpp b/src/network/core/tcp_connect.cpp --- a/src/network/core/tcp_connect.cpp +++ b/src/network/core/tcp_connect.cpp @@ -32,7 +32,7 @@ TCPConnecter::TCPConnecter(const Network sock(INVALID_SOCKET), address(address) { - *_tcp_connecters.Append() = this; + _tcp_connecters.push_back(this); if (!ThreadObject::New(TCPConnecter::ThreadEntry, this, &this->thread, "ottd:tcp")) { this->Connect(); } diff --git a/src/network/core/tcp_http.cpp b/src/network/core/tcp_http.cpp --- a/src/network/core/tcp_http.cpp +++ b/src/network/core/tcp_http.cpp @@ -63,7 +63,7 @@ NetworkHTTPSocketHandler::NetworkHTTPSoc return; } - *_http_connections.Append() = this; + _http_connections.push_back(this); } /** Free whatever needs to be freed. */ diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp --- a/src/network/core/udp.cpp +++ b/src/network/core/udp.cpp @@ -26,14 +26,14 @@ NetworkUDPSocketHandler::NetworkUDPSocke { if (bind != NULL) { for (NetworkAddress *addr = bind->Begin(); addr != bind->End(); addr++) { - *this->bind.Append() = *addr; + this->bind.push_back(*addr); } } else { /* As hostname NULL and port 0/NULL don't go well when * resolving it we need to add an address for each of * the address families we support. */ - *this->bind.Append() = NetworkAddress(NULL, 0, AF_INET); - *this->bind.Append() = NetworkAddress(NULL, 0, AF_INET6); + this->bind.emplace_back(nullptr, 0, AF_INET); + this->bind.emplace_back(nullptr, 0, AF_INET6); } } diff --git a/src/network/network.cpp b/src/network/network.cpp --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -633,12 +633,12 @@ void NetworkAddServer(const char *b) void GetBindAddresses(NetworkAddressList *addresses, uint16 port) { for (char **iter = _network_bind_list.Begin(); iter != _network_bind_list.End(); iter++) { - *addresses->Append() = NetworkAddress(*iter, port); + addresses->emplace_back(*iter, port); } /* No address, so bind to everything. */ if (addresses->size() == 0) { - *addresses->Append() = NetworkAddress("", port); + addresses->emplace_back("", port); } } @@ -650,7 +650,7 @@ void NetworkRebuildHostList() _network_host_list.Clear(); for (NetworkGameList *item = _network_game_list; item != NULL; item = item->next) { - if (item->manually) *_network_host_list.Append() = stredup(item->address.GetAddressAsString(false)); + if (item->manually) _network_host_list.push_back(stredup(item->address.GetAddressAsString(false))); } } diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -77,7 +77,7 @@ struct PacketReader : LoadFilter { /* Allocate a new chunk and add the remaining data. */ pbuf += to_write; to_write = in_packet - to_write; - this->buf = *this->blocks.Append() = CallocT(CHUNK); + this->blocks.push_back(this->buf = CallocT(CHUNK)); this->bufe = this->buf + CHUNK; memcpy(this->buf, pbuf, to_write); diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp --- a/src/network/network_content.cpp +++ b/src/network/network_content.cpp @@ -165,7 +165,7 @@ bool ClientNetworkContentSocketHandler:: return true; } - *this->infos.Append() = ci; + this->infos.push_back(ci); /* Incoming data means that we might need to reconsider dependencies */ for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) { @@ -278,7 +278,7 @@ void ClientNetworkContentSocketHandler:: } } if (!found) { - *this->infos.Append() = ci; + this->infos.push_back(ci); } else { delete ci; } @@ -300,7 +300,7 @@ void ClientNetworkContentSocketHandler:: const ContentInfo *ci = *iter; if (!ci->IsSelected() || ci->state == ContentInfo::ALREADY_HERE) continue; - *content.Append() = ci->id; + content.push_back(ci->id); bytes += ci->filesize; } @@ -579,11 +579,11 @@ void ClientNetworkContentSocketHandler:: if (this->http_response_index == -1) { if (data != NULL) { /* Append the rest of the response. */ - memcpy(this->http_response.Append((uint)length), data, length); + memcpy(grow(this->http_response, (uint)length), data, length); return; } else { /* Make sure the response is properly terminated. */ - *this->http_response.Append() = '\0'; + this->http_response.push_back('\0'); /* And prepare for receiving the rest of the data. */ this->http_response_index = 0; @@ -905,7 +905,7 @@ void ClientNetworkContentSocketHandler:: for (uint i = 0; i < ci->dependency_count; i++) { if (ci->dependencies[i] == child->id) { - *parents.Append() = ci; + parents.push_back(ci); break; } } @@ -919,7 +919,7 @@ void ClientNetworkContentSocketHandler:: */ void ClientNetworkContentSocketHandler::ReverseLookupTreeDependency(ConstContentVector &tree, const ContentInfo *child) const { - *tree.Append() = child; + tree.push_back(child); /* First find all direct parents. We can't use the "normal" iterator as * we are including stuff into the vector and as such the vector's data diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -391,7 +391,7 @@ class NetworkContentListWindow : public for (ConstContentIterator iter = _network_content_client.Begin(); iter != _network_content_client.End(); iter++) { if ((*iter)->state == ContentInfo::DOES_NOT_EXIST) all_available = false; - *this->content.Append() = *iter; + this->content.push_back(*iter); } this->SetWidgetDisabledState(WID_NCL_SEARCH_EXTERNAL, this->auto_select && all_available); diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -253,7 +253,7 @@ protected: this->servers.clear(); for (NetworkGameList *ngl = _network_game_list; ngl != NULL; ngl = ngl->next) { - *this->servers.Append() = ngl; + this->servers.push_back(ngl); } /* Apply the filter condition immediately, if a search string has been provided. */ @@ -1737,9 +1737,7 @@ struct NetworkClientListPopupWindow : Wi */ inline void AddAction(StringID name, ClientList_Action_Proc *proc) { - ClientListAction *action = this->actions.Append(); - action->name = name; - action->proc = proc; + this->actions.push_back({name, proc}); } NetworkClientListPopupWindow(WindowDesc *desc, int x, int y, ClientID client_id) : diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -2101,7 +2101,7 @@ uint NetworkServerKickOrBanIP(const char break; } } - if (!contains) *_network_ban_list.Append() = stredup(ip); + if (!contains) _network_ban_list.push_back(stredup(ip)); } uint n = 0; diff --git a/src/newgrf.cpp b/src/newgrf.cpp --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -472,10 +472,7 @@ static StringIDMappingVector _string_to_ static void AddStringForMapping(StringID source, StringID *target) { *target = STR_UNDEFINED; - StringIDMapping *item = _string_to_grf_mapping.Append(); - item->grfid = _cur.grffile->grfid; - item->source = source; - item->target = target; + _string_to_grf_mapping.push_back({_cur.grffile->grfid, source, target}); } /** @@ -659,11 +656,12 @@ static Engine *GetNewEngine(const GRFFil /* Reserve the engine slot */ assert(_engine_mngr.size() == e->index); - EngineIDMapping *eid = _engine_mngr.Append(); - eid->type = type; - eid->grfid = scope_grfid; // Note: this is INVALID_GRFID if dynamic_engines is disabled, so no reservation - eid->internal_id = internal_id; - eid->substitute_id = min(internal_id, _engine_counts[type]); // substitute_id == _engine_counts[subtype] means "no substitute" + _engine_mngr.push_back({ + scope_grfid, // Note: this is INVALID_GRFID if dynamic_engines is disabled, so no reservation + internal_id, + {static_cast(type)}, + static_cast(min(internal_id, _engine_counts[type])) // substitute_id == _engine_counts[subtype] means "no substitute" + }); if (engine_pool_size != Engine::GetPoolSize()) { /* Resize temporary engine data ... */ @@ -1909,18 +1907,19 @@ static ChangeInfoResult StationChangeInf tmp_layout.clear(); for (;;) { /* no relative bounding box support */ - DrawTileSeqStruct *dtss = tmp_layout.Append(); - MemSetT(dtss, 0); - - dtss->delta_x = buf->ReadByte(); - if (dtss->IsTerminator()) break; - dtss->delta_y = buf->ReadByte(); - dtss->delta_z = buf->ReadByte(); - dtss->size_x = buf->ReadByte(); - dtss->size_y = buf->ReadByte(); - dtss->size_z = buf->ReadByte(); - - ReadSpriteLayoutSprite(buf, false, true, false, GSF_STATIONS, &dtss->image); + /*C++17: DrawTileSeqStruct &dtss = */ tmp_layout.emplace_back(); + DrawTileSeqStruct &dtss = tmp_layout.back(); + MemSetT(&dtss, 0); + + dtss.delta_x = buf->ReadByte(); + if (dtss.IsTerminator()) break; + dtss.delta_y = buf->ReadByte(); + dtss.delta_z = buf->ReadByte(); + dtss.size_x = buf->ReadByte(); + dtss.size_y = buf->ReadByte(); + dtss.size_z = buf->ReadByte(); + + ReadSpriteLayoutSprite(buf, false, true, false, GSF_STATIONS, &dtss.image); /* On error, bail out immediately. Temporary GRF data was already freed */ if (_cur.skip_sprites < 0) return CIR_DISABLED; } @@ -2594,7 +2593,7 @@ static ChangeInfoResult LoadTranslationT translation_table.clear(); for (int i = 0; i < numinfo; i++) { uint32 item = buf->ReadDWord(); - *translation_table.Append() = BSWAP32(item); + translation_table.push_back(BSWAP32(item)); } return CIR_SUCCESS; @@ -2799,14 +2798,14 @@ static ChangeInfoResult GlobalVarChangeI if (map.openttd_id >= MAX_NUM_GENDERS) { grfmsg(1, "GlobalVarChangeInfo: Gender name %s is not known, ignoring", name); } else { - *_cur.grffile->language_map[curidx].gender_map.Append() = map; + _cur.grffile->language_map[curidx].gender_map.push_back(map); } } else { map.openttd_id = lang->GetCaseIndex(name); if (map.openttd_id >= MAX_NUM_CASES) { grfmsg(1, "GlobalVarChangeInfo: Case name %s is not known, ignoring", name); } else { - *_cur.grffile->language_map[curidx].case_map.Append() = map; + _cur.grffile->language_map[curidx].case_map.push_back(map); } } newgrf_id = buf->ReadByte(); @@ -4335,7 +4334,7 @@ static ChangeInfoResult RailTypeReserveI if (_cur.grffile->railtype_map[id + i] != INVALID_RAILTYPE) { int n = buf->ReadByte(); for (int j = 0; j != n; j++) { - *_railtypes[_cur.grffile->railtype_map[id + i]].alternate_labels.Append() = BSWAP32(buf->ReadDWord()); + _railtypes[_cur.grffile->railtype_map[id + i]].alternate_labels.push_back(BSWAP32(buf->ReadDWord())); } break; } @@ -4796,29 +4795,30 @@ static void NewSpriteGroup(ByteReader *b /* 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 { - DeterministicSpriteGroupAdjust *adjust = adjusts.Append(); + /*C++17: 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. */ - adjust->operation = adjusts.size() == 1 ? DSGA_OP_ADD : (DeterministicSpriteGroupAdjustOperation)buf->ReadByte(); - adjust->variable = buf->ReadByte(); - if (adjust->variable == 0x7E) { + adjust.operation = adjusts.size() == 1 ? DSGA_OP_ADD : (DeterministicSpriteGroupAdjustOperation)buf->ReadByte(); + adjust.variable = buf->ReadByte(); + if (adjust.variable == 0x7E) { /* Link subroutine group */ - adjust->subroutine = GetGroupFromGroupID(setid, type, buf->ReadByte()); + adjust.subroutine = GetGroupFromGroupID(setid, type, buf->ReadByte()); } else { - adjust->parameter = IsInsideMM(adjust->variable, 0x60, 0x80) ? buf->ReadByte() : 0; + adjust.parameter = IsInsideMM(adjust.variable, 0x60, 0x80) ? buf->ReadByte() : 0; } varadjust = buf->ReadByte(); - adjust->shift_num = GB(varadjust, 0, 5); - adjust->type = (DeterministicSpriteGroupAdjustType)GB(varadjust, 6, 2); - adjust->and_mask = buf->ReadVarSize(varsize); - - if (adjust->type != DSGA_TYPE_NONE) { - adjust->add_val = buf->ReadVarSize(varsize); - adjust->divmod_val = buf->ReadVarSize(varsize); + adjust.shift_num = GB(varadjust, 0, 5); + adjust.type = (DeterministicSpriteGroupAdjustType)GB(varadjust, 6, 2); + adjust.and_mask = buf->ReadVarSize(varsize); + + if (adjust.type != DSGA_TYPE_NONE) { + adjust.add_val = buf->ReadVarSize(varsize); + adjust.divmod_val = buf->ReadVarSize(varsize); } else { - adjust->add_val = 0; - adjust->divmod_val = 0; + adjust.add_val = 0; + adjust.divmod_val = 0; } /* Continue reading var adjusts while bit 5 is set. */ @@ -7851,9 +7851,7 @@ static bool HandleParameterInfo(ByteRead } if (id >= _cur.grfconfig->param_info.size()) { - uint num_to_add = id - _cur.grfconfig->param_info.size() + 1; - GRFParameterInfo **newdata = _cur.grfconfig->param_info.Append(num_to_add); - MemSetT(newdata, 0, num_to_add); + _cur.grfconfig->param_info.resize(id + 1); } if (_cur.grfconfig->param_info[id] == NULL) { _cur.grfconfig->param_info[id] = new GRFParameterInfo(id); @@ -8405,7 +8403,7 @@ static void InitNewGRFFile(const GRFConf } newfile = new GRFFile(config); - *_grf_files.Append() = _cur.grffile = newfile; + _grf_files.push_back(_cur.grffile = newfile); } /** diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp --- a/src/newgrf_commons.cpp +++ b/src/newgrf_commons.cpp @@ -666,7 +666,8 @@ uint32 NewGRFSpriteLayout::PrepareLayout /* Create a copy of the spritelayout, so we can modify some values. * Also include the groundsprite into the sequence for easier processing. */ - DrawTileSeqStruct *result = result_seq.Append(); + /*C++17: DrawTileSeqStruct *result = &*/ result_seq.emplace_back(); + DrawTileSeqStruct *result = &result_seq.back(); result->image = ground; result->delta_x = 0; result->delta_y = 0; @@ -674,10 +675,10 @@ uint32 NewGRFSpriteLayout::PrepareLayout const DrawTileSeqStruct *dtss; foreach_draw_tile_seq(dtss, this->seq) { - *result_seq.Append() = *dtss; + result_seq.push_back(*dtss); } - result_seq.Append()->MakeTerminator(); - + result_seq.emplace_back() /*C++17: .MakeTerminator()*/; + result_seq.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/newgrf_config.cpp b/src/newgrf_config.cpp --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -85,9 +85,9 @@ GRFConfig::GRFConfig(const GRFConfig &co if (config.error != NULL) this->error = new GRFError(*config.error); for (uint i = 0; i < config.param_info.size(); i++) { if (config.param_info[i] == NULL) { - *this->param_info.Append() = NULL; + this->param_info.push_back(NULL); } else { - *this->param_info.Append() = new GRFParameterInfo(*config.param_info[i]); + this->param_info.push_back(new GRFParameterInfo(*config.param_info[i])); } } } @@ -611,9 +611,9 @@ compatible_grf: c->has_param_defaults = f->has_param_defaults; for (uint i = 0; i < f->param_info.size(); i++) { if (f->param_info[i] == NULL) { - *c->param_info.Append() = NULL; + c->param_info.push_back(NULL); } else { - *c->param_info.Append() = new GRFParameterInfo(*f->param_info[i]); + c->param_info.push_back(new GRFParameterInfo(*f->param_info[i])); } } } diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -1196,9 +1196,7 @@ static SmallVector void AlterVehicleListOrder(EngineID engine, uint target) { /* Add the list order change to a queue */ - ListOrderChange *loc = _list_order_changes.Append(); - loc->engine = engine; - loc->target = target; + _list_order_changes.push_back({engine, target}); } /** @@ -1231,7 +1229,7 @@ void CommitVehicleListOrderChanges() SmallVector ordering; Engine *e; FOR_ALL_ENGINES(e) { - *ordering.Append() = e->index; + ordering.push_back(e->index); } QSortT(ordering.Begin(), ordering.size(), EnginePreSort); diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -378,7 +378,7 @@ struct NewGRFParametersWindow : public W DropDownList *list = new DropDownList(); for (uint32 i = par_info->min_value; i <= par_info->max_value; i++) { - *list->Append() = new DropDownListCharStringItem(GetGRFStringFromGRFText(par_info->value_names.Find(i)->second), i, false); + list->push_back(new DropDownListCharStringItem(GetGRFStringFromGRFText(par_info->value_names.Find(i)->second), i, false)); } ShowDropDownListAt(this, list, old_val, -1, wi_rect, COLOUR_ORANGE, true); @@ -927,11 +927,11 @@ struct NewGRFWindow : public Window, New DropDownList *list = new DropDownList(); /* Add 'None' option for clearing list */ - *list->Append() = new DropDownListStringItem(STR_NONE, -1, false); + list->push_back(new DropDownListStringItem(STR_NONE, -1, false)); for (uint i = 0; i < _grf_preset_list.size(); i++) { if (_grf_preset_list[i] != NULL) { - *list->Append() = new DropDownListCharStringItem(_grf_preset_list[i], i, false); + list->push_back(new DropDownListCharStringItem(_grf_preset_list[i], i, false)); } } @@ -1464,7 +1464,7 @@ private: if (found) continue; if (_settings_client.gui.newgrf_show_old_versions) { - *this->avails.Append() = c; + this->avails.push_back(c); } else { const GRFConfig *best = FindGRFConfig(c->ident.grfid, HasBit(c->flags, GCF_INVALID) ? FGCM_NEWEST : FGCM_NEWEST_VALID); /* @@ -1475,7 +1475,7 @@ private: * show that NewGRF!. */ if (best->version == 0 || best->ident.HasGrfIdentifier(c->ident.grfid, c->ident.md5sum)) { - *this->avails.Append() = c; + this->avails.push_back(c); } } } @@ -1558,7 +1558,7 @@ void ShowMissingContentWindow(const GRFC strecpy(ci->name, c->GetName(), lastof(ci->name)); ci->unique_id = BSWAP32(c->ident.grfid); memcpy(ci->md5sum, HasBit(c->flags, GCF_COMPATIBLE) ? c->original_md5sum : c->ident.md5sum, sizeof(ci->md5sum)); - *cv.Append() = ci; + cv.push_back(ci); } ShowNetworkContentListWindow(cv.size() == 0 ? NULL : &cv, CONTENT_TYPE_NEWGRF); } diff --git a/src/newgrf_sound.cpp b/src/newgrf_sound.cpp --- a/src/newgrf_sound.cpp +++ b/src/newgrf_sound.cpp @@ -32,7 +32,7 @@ static SmallVector _sound */ SoundEntry *AllocateSound(uint num) { - SoundEntry *sound = _sounds.Append(num); + SoundEntry *sound = grow(_sounds, num); MemSetT(sound, 0, num); return sound; } diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp --- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -530,9 +530,7 @@ static CommandCost ClearTile_Object(Tile break; } - ClearedObjectArea *cleared_area = _cleared_object_areas.Append(); - cleared_area->first_tile = tile; - cleared_area->area = ta; + _cleared_object_areas.push_back({tile, ta}); if (flags & DC_EXEC) ReallyClearObjectTile(o); diff --git a/src/openttd.cpp b/src/openttd.cpp --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -445,7 +445,7 @@ struct AfterNewGRFScan : NewGRFScanCallb if (dedicated_host != NULL) { _network_bind_list.Clear(); - *_network_bind_list.Append() = stredup(dedicated_host); + _network_bind_list.push_back(stredup(dedicated_host)); } if (dedicated_port != 0) _settings_client.network.server_port = dedicated_port; @@ -1177,7 +1177,7 @@ static void CheckCaches() SmallVector old_town_caches; Town *t; FOR_ALL_TOWNS(t) { - MemCpyT(old_town_caches.Append(), &t->cache); + old_town_caches.push_back(t->cache); } extern void RebuildTownCaches(); @@ -1195,7 +1195,7 @@ static void CheckCaches() /* Check company infrastructure cache. */ SmallVector old_infrastructure; Company *c; - FOR_ALL_COMPANIES(c) MemCpyT(old_infrastructure.Append(), &c->infrastructure); + FOR_ALL_COMPANIES(c) old_infrastructure.push_back(c->infrastructure); extern void AfterLoadCompanyStats(); AfterLoadCompanyStats(); diff --git a/src/order_gui.cpp b/src/order_gui.cpp --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -1297,7 +1297,7 @@ public: case WID_O_COND_VARIABLE: { DropDownList *list = new DropDownList(); for (uint i = 0; i < lengthof(_order_conditional_variable); i++) { - *list->Append() = new DropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i], _order_conditional_variable[i], false); + list->push_back(new DropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i], _order_conditional_variable[i], false)); } ShowDropDownList(this, list, this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), WID_O_COND_VARIABLE); break; diff --git a/src/os/macosx/string_osx.cpp b/src/os/macosx/string_osx.cpp --- a/src/os/macosx/string_osx.cpp +++ b/src/os/macosx/string_osx.cpp @@ -78,7 +78,7 @@ public: FontMap::const_iterator map = fontMapping.Begin(); while (map < fontMapping.End() - 1 && map->first <= chars.location) map++; - *this->Append() = new CoreTextVisualRun(run, map->second, buff); + this->push_back(new CoreTextVisualRun(run, map->second, buff)); } CFRelease(line); } diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -1623,7 +1623,7 @@ CommandCost CmdConvertRail(TileIndex til if (v != NULL && !HasPowerOnRail(v->railtype, totype)) { /* No power on new rail type, reroute. */ FreeTrainTrackReservation(v); - *vehicles_affected.Append() = v; + vehicles_affected.push_back(v); } } @@ -1705,7 +1705,7 @@ CommandCost CmdConvertRail(TileIndex til if (v != NULL && !HasPowerOnRail(v->railtype, totype)) { /* No power on new rail type, reroute. */ FreeTrainTrackReservation(v); - *vehicles_affected.Append() = v; + vehicles_affected.push_back(v); } } diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -2007,7 +2007,7 @@ DropDownList *GetRailTypeDropDownList(bo if (all_option) { DropDownListStringItem *item = new DropDownListStringItem(STR_REPLACE_ALL_RAILTYPE, INVALID_RAILTYPE, false); - *list->Append() = item; + list->push_back(item); } Dimension d = { 0, 0 }; @@ -2038,7 +2038,7 @@ DropDownList *GetRailTypeDropDownList(bo } item->SetParam(0, rti->strings.menu_text); item->SetParam(1, rti->max_speed); - *list->Append() = item; + list->push_back(item); } return list; } diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2954,24 +2954,24 @@ bool AfterLoadGame() cur_skip = prev_tile_skip; } - uint *this_skip = skip_frames.Append(); - *this_skip = prev_tile_skip; + /*C++17: uint &this_skip = */ skip_frames.push_back(prev_tile_skip); + uint &this_skip = skip_frames.back(); /* The following 3 curves now take longer than before */ switch (u->state) { case 2: cur_skip++; - if (u->frame <= (roadside ? 9 : 5)) *this_skip = cur_skip; + if (u->frame <= (roadside ? 9 : 5)) this_skip = cur_skip; break; case 4: cur_skip++; - if (u->frame <= (roadside ? 5 : 9)) *this_skip = cur_skip; + if (u->frame <= (roadside ? 5 : 9)) this_skip = cur_skip; break; case 5: cur_skip++; - if (u->frame <= (roadside ? 4 : 2)) *this_skip = cur_skip; + if (u->frame <= (roadside ? 4 : 2)) this_skip = cur_skip; break; default: diff --git a/src/saveload/animated_tile_sl.cpp b/src/saveload/animated_tile_sl.cpp --- a/src/saveload/animated_tile_sl.cpp +++ b/src/saveload/animated_tile_sl.cpp @@ -42,14 +42,14 @@ static void Load_ANIT() for (int i = 0; i < 256; i++) { if (anim_list[i] == 0) break; - *_animated_tiles.Append() = anim_list[i]; + _animated_tiles.push_back(anim_list[i]); } return; } uint count = (uint)SlGetFieldLength() / sizeof(*_animated_tiles.Begin()); _animated_tiles.clear(); - _animated_tiles.Append(count); + _animated_tiles.resize(_animated_tiles.size() + count); SlArray(_animated_tiles.Begin(), count, SLE_UINT32); } diff --git a/src/saveload/engine_sl.cpp b/src/saveload/engine_sl.cpp --- a/src/saveload/engine_sl.cpp +++ b/src/saveload/engine_sl.cpp @@ -190,7 +190,8 @@ static void Load_EIDS() _engine_mngr.clear(); while (SlIterateArray() != -1) { - EngineIDMapping *eid = _engine_mngr.Append(); + /*C++17: EngineIDMapping *eid = &*/ _engine_mngr.emplace_back(); + EngineIDMapping *eid = &_engine_mngr.back(); SlObject(eid, _engine_id_mapping_desc); } } diff --git a/src/saveload/game_sl.cpp b/src/saveload/game_sl.cpp --- a/src/saveload/game_sl.cpp +++ b/src/saveload/game_sl.cpp @@ -153,10 +153,10 @@ static void Load_GSTR() LanguageStrings *ls = new LanguageStrings(_game_saveload_string != NULL ? _game_saveload_string : ""); for (uint i = 0; i < _game_saveload_strings; i++) { SlObject(NULL, _game_language_string); - *ls->lines.Append() = stredup(_game_saveload_string != NULL ? _game_saveload_string : ""); + ls->lines.push_back(stredup(_game_saveload_string != NULL ? _game_saveload_string : "")); } - *_current_data->raw_strings.Append() = ls; + _current_data->raw_strings.push_back(ls); } /* If there were no strings in the savegame, set GameStrings to NULL */ diff --git a/src/saveload/labelmaps_sl.cpp b/src/saveload/labelmaps_sl.cpp --- a/src/saveload/labelmaps_sl.cpp +++ b/src/saveload/labelmaps_sl.cpp @@ -48,7 +48,7 @@ void AfterLoadLabelMaps() RailType r = GetRailTypeByLabel(_railtype_list[i]); if (r == INVALID_RAILTYPE) r = RAILTYPE_BEGIN; - *railtype_conversion_map.Append() = r; + railtype_conversion_map.push_back(r); } for (TileIndex t = 0; t < MapSize(); t++) { @@ -114,7 +114,7 @@ static void Load_RAIL() while (SlIterateArray() != -1) { SlObject(&lo, _label_object_desc); - *_railtype_list.Append() = (RailTypeLabel)lo.label; + _railtype_list.push_back((RailTypeLabel)lo.label); } } diff --git a/src/saveload/linkgraph_sl.cpp b/src/saveload/linkgraph_sl.cpp --- a/src/saveload/linkgraph_sl.cpp +++ b/src/saveload/linkgraph_sl.cpp @@ -69,7 +69,7 @@ const SaveLoad *GetLinkGraphJobDesc() char *&address = reinterpret_cast(sl.address); address -= offset_gamesettings; address += offset_component; - *(saveloads.Append()) = sl; + saveloads.push_back(sl); } desc = GetSettingDescription(++setting); } @@ -82,7 +82,7 @@ const SaveLoad *GetLinkGraphJobDesc() int i = 0; do { - *(saveloads.Append()) = job_desc[i++]; + saveloads.push_back(job_desc[i++]); } while (saveloads[saveloads.size() - 1].cmd != SL_END); } diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp --- a/src/saveload/oldloader_sl.cpp +++ b/src/saveload/oldloader_sl.cpp @@ -651,7 +651,7 @@ static bool LoadOldAnimTileList(Loadgame /* The first zero in the loaded array indicates the end of the list. */ for (int i = 0; i < 256; i++) { if (anim_list[i] == 0) break; - *_animated_tiles.Append() = anim_list[i]; + _animated_tiles.push_back(anim_list[i]); } return true; diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -143,7 +143,7 @@ struct MemoryDumper { /* Are we at the end of this chunk? */ if (this->buf == this->bufe) { this->buf = CallocT(MEMORY_CHUNK_SIZE); - *this->blocks.Append() = this->buf; + this->blocks.push_back(this->buf); this->bufe = this->buf + MEMORY_CHUNK_SIZE; } diff --git a/src/saveload/waypoint_sl.cpp b/src/saveload/waypoint_sl.cpp --- a/src/saveload/waypoint_sl.cpp +++ b/src/saveload/waypoint_sl.cpp @@ -178,7 +178,8 @@ static void Load_WAYP() int index; while ((index = SlIterateArray()) != -1) { - OldWaypoint *wp = _old_waypoints.Append(); + /*C++17: OldWaypoint *wp = &*/ _old_waypoints.emplace_back(); + OldWaypoint *wp = &_old_waypoints.back(); memset(wp, 0, sizeof(*wp)); wp->index = index; diff --git a/src/script/squirrel_helper.hpp b/src/script/squirrel_helper.hpp --- a/src/script/squirrel_helper.hpp +++ b/src/script/squirrel_helper.hpp @@ -117,7 +117,7 @@ namespace SQConvert { sq_getstring(vm, -1, &tmp); char *tmp_str = stredup(tmp); sq_poptop(vm); - *ptr->Append() = (void *)tmp_str; + ptr->push_back((void *)tmp_str); str_validate(tmp_str, tmp_str + strlen(tmp_str)); return tmp_str; } @@ -137,7 +137,7 @@ namespace SQConvert { while (SQ_SUCCEEDED(sq_next(vm, -2))) { SQInteger tmp; if (SQ_SUCCEEDED(sq_getinteger(vm, -1, &tmp))) { - *data.Append() = (int32)tmp; + data.push_back((int32)tmp); } else { sq_pop(vm, 4); throw sq_throwerror(vm, "a member of an array used as parameter to a function is not numeric"); @@ -151,7 +151,7 @@ namespace SQConvert { arr->size = data.size(); memcpy(arr->array, data.Begin(), sizeof(int32) * data.size()); - *ptr->Append() = arr; + ptr->push_back(arr); return arr; } diff --git a/src/settings.cpp b/src/settings.cpp --- a/src/settings.cpp +++ b/src/settings.cpp @@ -727,7 +727,7 @@ static void IniLoadSettingList(IniFile * list->Clear(); for (const IniItem *item = group->item; item != NULL; item = item->next) { - if (item->name != NULL) *list->Append() = stredup(item->name); + if (item->name != NULL) list->push_back(stredup(item->name)); } } @@ -1777,7 +1777,7 @@ void GetGRFPresetList(GRFPresetList *lis IniGroup *group; for (group = ini->group; group != NULL; group = group->next) { if (strncmp(group->name, "preset-", 7) == 0) { - *list->Append() = stredup(group->name + 7); + list->push_back(stredup(group->name + 7)); } } diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -129,7 +129,7 @@ static DropDownList *BuildSetDropDownLis DropDownList *list = new DropDownList(); for (int i = 0; i < n; i++) { - *list->Append() = new DropDownListCharStringItem(T::GetSet(i)->name, i, !allow_selection && (*selected_index != i)); + list->push_back(new DropDownListCharStringItem(T::GetSet(i)->name, i, !allow_selection && (*selected_index != i))); } return list; @@ -213,13 +213,13 @@ struct GameOptionsWindow : Window { /* Add non-custom currencies; sorted naturally */ for (uint i = 0; i < CURRENCY_END; items++, i++) { if (i == CURRENCY_CUSTOM) continue; - *list->Append() = new DropDownListStringItem(*items, i, HasBit(disabled, i)); + list->push_back(new DropDownListStringItem(*items, i, HasBit(disabled, i))); } QSortT(list->Begin(), list->size(), DropDownListStringItem::NatSortFunc); /* Append custom currency at the end */ - *list->Append() = new DropDownListItem(-1, false); // separator line - *list->Append() = new DropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CUSTOM, CURRENCY_CUSTOM, HasBit(disabled, CURRENCY_CUSTOM)); + list->push_back(new DropDownListItem(-1, false)); // separator line + list->push_back(new DropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CUSTOM, CURRENCY_CUSTOM, HasBit(disabled, CURRENCY_CUSTOM))); break; } @@ -237,7 +237,7 @@ struct GameOptionsWindow : Window { } for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) { - *list->Append() = new DropDownListStringItem(*items, i, HasBit(disabled, i)); + list->push_back(new DropDownListStringItem(*items, i, HasBit(disabled, i))); } break; } @@ -251,20 +251,20 @@ struct GameOptionsWindow : Window { /* Add and sort newgrf townnames generators */ for (int i = 0; i < _nb_grf_names; i++) { int result = _nb_orig_names + i; - *list->Append() = new DropDownListStringItem(_grf_names[i], result, enabled_item != result && enabled_item >= 0); + list->push_back(new DropDownListStringItem(_grf_names[i], result, enabled_item != result && enabled_item >= 0)); } QSortT(list->Begin(), list->size(), DropDownListStringItem::NatSortFunc); int newgrf_size = list->size(); /* Insert newgrf_names at the top of the list */ if (newgrf_size > 0) { - *list->Append() = new DropDownListItem(-1, false); // separator line + list->push_back(new DropDownListItem(-1, false)); // separator line newgrf_size++; } /* Add and sort original townnames generators */ for (int i = 0; i < _nb_orig_names; i++) { - *list->Append() = new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + i, i, enabled_item != i && enabled_item >= 0); + list->push_back(new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + i, i, enabled_item != i && enabled_item >= 0)); } QSortT(list->Begin() + newgrf_size, list->size() - newgrf_size, DropDownListStringItem::NatSortFunc); break; @@ -275,7 +275,7 @@ struct GameOptionsWindow : Window { *selected_index = _settings_client.gui.autosave; const StringID *items = _autosave_dropdown; for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) { - *list->Append() = new DropDownListStringItem(*items, i, false); + list->push_back(new DropDownListStringItem(*items, i, false)); } break; } @@ -284,7 +284,7 @@ struct GameOptionsWindow : Window { list = new DropDownList(); for (uint i = 0; i < _languages.size(); i++) { if (&_languages[i] == _current_language) *selected_index = i; - *list->Append() = new DropDownListStringItem(SPECSTR_LANGUAGE_START + i, i, false); + list->push_back(new DropDownListStringItem(SPECSTR_LANGUAGE_START + i, i, false)); } QSortT(list->Begin(), list->size(), DropDownListStringItem::NatSortFunc); break; @@ -296,7 +296,7 @@ struct GameOptionsWindow : Window { list = new DropDownList(); *selected_index = GetCurRes(); for (int i = 0; i < _num_resolutions; i++) { - *list->Append() = new DropDownListStringItem(SPECSTR_RESOLUTION_START + i, i, false); + list->push_back(new DropDownListStringItem(SPECSTR_RESOLUTION_START + i, i, false)); } break; @@ -305,7 +305,7 @@ struct GameOptionsWindow : Window { *selected_index = ZOOM_LVL_OUT_4X - _gui_zoom; const StringID *items = _gui_zoom_dropdown; for (int i = 0; *items != INVALID_STRING_ID; items++, i++) { - *list->Append() = new DropDownListStringItem(*items, i, _settings_client.gui.zoom_min > ZOOM_LVL_OUT_4X - i); + list->push_back(new DropDownListStringItem(*items, i, _settings_client.gui.zoom_min > ZOOM_LVL_OUT_4X - i)); } break; } @@ -315,7 +315,7 @@ struct GameOptionsWindow : Window { *selected_index = ZOOM_LVL_OUT_4X - _font_zoom; const StringID *items = _font_zoom_dropdown; for (int i = 0; *items != INVALID_STRING_ID; items++, i++) { - *list->Append() = new DropDownListStringItem(*items, i, false); + list->push_back(new DropDownListStringItem(*items, i, false)); } break; } @@ -1964,16 +1964,16 @@ struct GameSettingsWindow : Window { * we don't want to allow comparing with new game's settings. */ bool disabled = mode == RM_CHANGED_AGAINST_NEW && settings_ptr == &_settings_newgame; - *list->Append() = new DropDownListStringItem(_game_settings_restrict_dropdown[mode], mode, disabled); + list->push_back(new DropDownListStringItem(_game_settings_restrict_dropdown[mode], mode, disabled)); } break; case WID_GS_TYPE_DROPDOWN: list = new DropDownList(); - *list->Append() = new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL, ST_ALL, false); - *list->Append() = new DropDownListStringItem(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME, ST_GAME, false); - *list->Append() = new DropDownListStringItem(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME, ST_COMPANY, false); - *list->Append() = new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT, ST_CLIENT, false); + list->push_back(new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL, ST_ALL, false)); + list->push_back(new DropDownListStringItem(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME, ST_GAME, false)); + list->push_back(new DropDownListStringItem(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME, ST_COMPANY, false)); + list->push_back(new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT, ST_CLIENT, false)); break; } return list; @@ -2130,7 +2130,7 @@ struct GameSettingsWindow : Window { DropDownList *list = new DropDownList(); for (int i = sdb->min; i <= (int)sdb->max; i++) { - *list->Append() = new DropDownListStringItem(sdb->str_val + i - sdb->min, i, false); + list->push_back(new DropDownListStringItem(sdb->str_val + i - sdb->min, i, false)); } ShowDropDownListAt(this, list, value, -1, wi_rect, COLOUR_ORANGE, true); diff --git a/src/settingsgen/settingsgen.cpp b/src/settingsgen/settingsgen.cpp --- a/src/settingsgen/settingsgen.cpp +++ b/src/settingsgen/settingsgen.cpp @@ -121,9 +121,10 @@ public: text += stored_size; } while (length > 0) { - OutputBuffer *block = this->output_buffer.Append(); - block->Clear(); // Initialize the new block. - int stored_size = block->Add(text, length); + /*C++17: OutputBuffer &block =*/ this->output_buffer.emplace_back(); + OutputBuffer &block = this->output_buffer.back(); + block.Clear(); // Initialize the new block. + int stored_size = block.Add(text, length); length -= stored_size; text += stored_size; } diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -63,7 +63,7 @@ struct SignList { this->signs.clear(); const Sign *si; - FOR_ALL_SIGNS(si) *this->signs.Append() = si; + FOR_ALL_SIGNS(si) this->signs.push_back(si); this->signs.SetFilterState(true); this->FilterSignList(); diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -942,7 +942,7 @@ static CommandCost CheckFlatLandRailStat if (HasBit(GetRailReservationTrackBits(tile_cur), track)) { Train *v = GetTrainForReservation(tile_cur, track); if (v != NULL) { - *affected_vehicles.Append() = v; + affected_vehicles.push_back(v); } } CommandCost ret = DoCommand(tile_cur, 0, track, flags, CMD_REMOVE_SINGLE_RAIL); @@ -1386,7 +1386,7 @@ CommandCost CmdBuildRailStation(TileInde /* Check for trains having a reservation for this tile. */ Train *v = GetTrainForReservation(tile, AxisToTrack(GetRailStationAxis(tile))); if (v != NULL) { - *affected_vehicles.Append() = v; + affected_vehicles.push_back(v); FreeTrainReservation(v); } } @@ -3538,7 +3538,7 @@ void DeleteStaleLinks(Station *from) } } if (!found_to || !found_from) continue; - *(vehicles.Append()) = l->GetFirstSharedVehicle(); + vehicles.push_back(l->GetFirstSharedVehicle()); } auto iter = vehicles.begin(); diff --git a/src/station_gui.cpp b/src/station_gui.cpp --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -189,14 +189,14 @@ protected: if (st->goods[j].HasRating()) { num_waiting_cargo++; // count number of waiting cargo if (HasBit(this->cargo_filter, j)) { - *this->stations.Append() = st; + this->stations.push_back(st); break; } } } /* stations without waiting cargo */ if (num_waiting_cargo == 0 && this->include_empty) { - *this->stations.Append() = st; + this->stations.push_back(st); } } } @@ -2135,7 +2135,7 @@ static bool AddNearbyStation(TileIndex t for (uint i = 0; i < _deleted_stations_nearby.size(); i++) { auto ts = _deleted_stations_nearby.begin() + i; if (ts->tile == tile) { - *_stations_nearby_list.Append() = _deleted_stations_nearby[i].station; + _stations_nearby_list.push_back(_deleted_stations_nearby[i].station); _deleted_stations_nearby.erase(ts); i--; } @@ -2153,7 +2153,7 @@ static bool AddNearbyStation(TileIndex t if (st->owner != _local_company || std::find(_stations_nearby_list.begin(), _stations_nearby_list.end(), sid) != _stations_nearby_list.end()) return false; if (st->rect.BeforeAddRect(ctx->tile, ctx->w, ctx->h, StationRect::ADD_TEST).Succeeded()) { - *_stations_nearby_list.Append() = sid; + _stations_nearby_list.push_back(sid); } return false; // We want to include *all* nearby stations @@ -2187,9 +2187,7 @@ static const T *FindStationsNearby(TileA if (T::IsExpected(st) && !st->IsInUse() && st->owner == _local_company) { /* Include only within station spread (yes, it is strictly less than) */ if (max(DistanceMax(ta.tile, st->xy), DistanceMax(TILE_ADDXY(ta.tile, ta.w - 1, ta.h - 1), st->xy)) < _settings_game.station.station_spread) { - TileAndStation *ts = _deleted_stations_nearby.Append(); - ts->tile = st->xy; - ts->station = st->index; + _deleted_stations_nearby.push_back({st->xy, st->index}); /* Add the station when it's within where we're going to build */ if (IsInsideBS(TileX(st->xy), TileX(ctx.tile), ctx.w) && diff --git a/src/story_gui.cpp b/src/story_gui.cpp --- a/src/story_gui.cpp +++ b/src/story_gui.cpp @@ -57,7 +57,7 @@ protected: const StoryPage *p; FOR_ALL_STORY_PAGES(p) { if (this->IsPageAvailable(p)) { - *this->story_pages.Append() = p; + this->story_pages.push_back(p); } } @@ -85,7 +85,7 @@ protected: const StoryPageElement *pe; FOR_ALL_STORY_PAGE_ELEMENTS(pe) { if (pe->page == p->index) { - *this->story_page_elements.Append() = pe; + this->story_page_elements.push_back(pe); } } } @@ -248,7 +248,7 @@ protected: item = str_item; } - *list->Append() = item; + list->push_back(item); page_num++; } diff --git a/src/strgen/strgen_base.cpp b/src/strgen/strgen_base.cpp --- a/src/strgen/strgen_base.cpp +++ b/src/strgen/strgen_base.cpp @@ -242,7 +242,7 @@ struct Buffer : SmallVector { */ void AppendByte(byte value) { - *this->Append() = value; + this->push_back(value); } /** @@ -252,19 +252,19 @@ struct Buffer : SmallVector { void AppendUtf8(uint32 value) { if (value < 0x80) { - *this->Append() = value; + this->push_back(value); } else if (value < 0x800) { - *this->Append() = 0xC0 + GB(value, 6, 5); - *this->Append() = 0x80 + GB(value, 0, 6); + this->push_back(0xC0 + GB(value, 6, 5)); + this->push_back(0x80 + GB(value, 0, 6)); } else if (value < 0x10000) { - *this->Append() = 0xE0 + GB(value, 12, 4); - *this->Append() = 0x80 + GB(value, 6, 6); - *this->Append() = 0x80 + GB(value, 0, 6); + this->push_back(0xE0 + GB(value, 12, 4)); + this->push_back(0x80 + GB(value, 6, 6)); + this->push_back(0x80 + GB(value, 0, 6)); } else if (value < 0x110000) { - *this->Append() = 0xF0 + GB(value, 18, 3); - *this->Append() = 0x80 + GB(value, 12, 6); - *this->Append() = 0x80 + GB(value, 6, 6); - *this->Append() = 0x80 + GB(value, 0, 6); + this->push_back(0xF0 + GB(value, 18, 3)); + this->push_back(0x80 + GB(value, 12, 6)); + this->push_back(0x80 + GB(value, 6, 6)); + this->push_back(0x80 + GB(value, 0, 6)); } else { strgen_warning("Invalid unicode value U+0x%X", value); } diff --git a/src/string.cpp b/src/string.cpp --- a/src/string.cpp +++ b/src/string.cpp @@ -634,8 +634,8 @@ public: this->char_itr = icu::BreakIterator::createCharacterInstance(icu::Locale(_current_language != NULL ? _current_language->isocode : "en"), status); this->word_itr = icu::BreakIterator::createWordInstance(icu::Locale(_current_language != NULL ? _current_language->isocode : "en"), status); - *this->utf16_str.Append() = '\0'; - *this->utf16_to_utf8.Append() = 0; + this->utf16_str.push_back('\0'); + this->utf16_to_utf8.push_back(0); } virtual ~IcuStringIterator() @@ -660,17 +660,17 @@ public: WChar c = Utf8Consume(&s); if (c < 0x10000) { - *this->utf16_str.Append() = (UChar)c; + this->utf16_str.push_back((UChar)c); } else { /* Make a surrogate pair. */ - *this->utf16_str.Append() = (UChar)(0xD800 + ((c - 0x10000) >> 10)); - *this->utf16_str.Append() = (UChar)(0xDC00 + ((c - 0x10000) & 0x3FF)); - *this->utf16_to_utf8.Append() = idx; + this->utf16_str.push_back((UChar)(0xD800 + ((c - 0x10000) >> 10))); + this->utf16_str.push_back((UChar)(0xDC00 + ((c - 0x10000) & 0x3FF))); + this->utf16_to_utf8.push_back(idx); } - *this->utf16_to_utf8.Append() = idx; + this->utf16_to_utf8.push_back(idx); } - *this->utf16_str.Append() = '\0'; - *this->utf16_to_utf8.Append() = s - string_base; + this->utf16_str.push_back('\0'); + this->utf16_to_utf8.push_back(s - string_base); UText text = UTEXT_INITIALIZER; UErrorCode status = U_ZERO_ERROR; diff --git a/src/stringfilter.cpp b/src/stringfilter.cpp --- a/src/stringfilter.cpp +++ b/src/stringfilter.cpp @@ -76,9 +76,8 @@ void StringFilter::SetFilterTerm(const c /* Add to word */ if (word == NULL) { - word = this->word_index.Append(); - word->start = dest; - word->match = false; + /*C++17: word = &*/ this->word_index.push_back({dest, false}); + word = &this->word_index.back(); } memcpy(dest, pos, len); diff --git a/src/strings.cpp b/src/strings.cpp --- a/src/strings.cpp +++ b/src/strings.cpp @@ -1932,7 +1932,7 @@ static void GetLanguageList(const char * } else if (GetLanguage(lmd.newgrflangid) != NULL) { DEBUG(misc, 3, "%s's language ID is already known", lmd.file); } else { - *_languages.Append() = lmd; + _languages.push_back(lmd); } } closedir(dir); diff --git a/src/texteff.cpp b/src/texteff.cpp --- a/src/texteff.cpp +++ b/src/texteff.cpp @@ -48,20 +48,20 @@ TextEffectID AddTextEffect(StringID msg, for (i = 0; i < _text_effects.size(); i++) { if (_text_effects[i].string_id == INVALID_STRING_ID) break; } - if (i == _text_effects.size()) _text_effects.Append(); + if (i == _text_effects.size()) _text_effects.emplace_back(); - TextEffect *te = _text_effects.data() + i; + TextEffect &te = _text_effects[i]; /* Start defining this object */ - te->string_id = msg; - te->duration = duration; - te->params_1 = GetDParam(0); - te->params_2 = GetDParam(1); - te->mode = mode; + te.string_id = msg; + te.duration = duration; + te.params_1 = GetDParam(0); + te.params_2 = GetDParam(1); + te.mode = mode; /* Make sure we only dirty the new area */ - te->width_normal = 0; - te->UpdatePosition(center, y, msg); + te.width_normal = 0; + te.UpdatePosition(center, y, msg); return i; } diff --git a/src/textfile_gui.cpp b/src/textfile_gui.cpp --- a/src/textfile_gui.cpp +++ b/src/textfile_gui.cpp @@ -365,11 +365,11 @@ static void Xunzip(byte **bufp, size_t * str_validate(p, this->text + filesize, SVS_REPLACE_WITH_QUESTION_MARK | SVS_ALLOW_NEWLINE); /* Split the string on newlines. */ - *this->lines.Append() = p; + this->lines.push_back(p); for (; *p != '\0'; p++) { if (*p == '\n') { *p = '\0'; - *this->lines.Append() = p + 1; + this->lines.push_back(p + 1); } } diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -285,10 +285,10 @@ CommandCost CmdSetTimetableStart(TileInd if (timetable_all) { for (Vehicle *w = v->orders.list->GetFirstSharedVehicle(); w != NULL; w = w->NextShared()) { - *vehs.Append() = w; + vehs.push_back(w); } } else { - *vehs.Append() = v; + vehs.push_back(v); } int total_duration = v->orders.list->GetTimetableTotalDuration(); diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -198,7 +198,7 @@ static void PopupMainToolbMenu(Window *w { DropDownList *list = new DropDownList(); for (int i = 0; i < count; i++) { - *list->Append() = new DropDownListStringItem(string + i, i, false); + list->push_back(new DropDownListStringItem(string + i, i, false)); } PopupMainToolbMenu(w, widget, list, 0); } @@ -224,27 +224,27 @@ static void PopupMainCompanyToolbMenu(Wi if (!_networking) break; /* Add the client list button for the companies menu */ - *list->Append() = new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_CLIENT_LIST, CTMN_CLIENT_LIST, false); + list->push_back(new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_CLIENT_LIST, CTMN_CLIENT_LIST, false)); if (_local_company == COMPANY_SPECTATOR) { - *list->Append() = new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_NEW_COMPANY, CTMN_NEW_COMPANY, NetworkMaxCompaniesReached()); + list->push_back(new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_NEW_COMPANY, CTMN_NEW_COMPANY, NetworkMaxCompaniesReached())); } else { - *list->Append() = new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_SPECTATE, CTMN_SPECTATE, NetworkMaxSpectatorsReached()); + list->push_back(new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_SPECTATE, CTMN_SPECTATE, NetworkMaxSpectatorsReached())); } break; case WID_TN_STORY: - *list->Append() = new DropDownListStringItem(STR_STORY_BOOK_SPECTATOR, CTMN_SPECTATOR, false); + list->push_back(new DropDownListStringItem(STR_STORY_BOOK_SPECTATOR, CTMN_SPECTATOR, false)); break; case WID_TN_GOAL: - *list->Append() = new DropDownListStringItem(STR_GOALS_SPECTATOR, CTMN_SPECTATOR, false); + list->push_back(new DropDownListStringItem(STR_GOALS_SPECTATOR, CTMN_SPECTATOR, false)); break; } for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) { if (!Company::IsValidID(c)) continue; - *list->Append() = new DropDownListCompanyItem(c, false, HasBit(grey, c)); + list->push_back(new DropDownListCompanyItem(c, false, HasBit(grey, c))); } PopupMainToolbMenu(w, widget, list, _local_company == COMPANY_SPECTATOR ? (widget == WID_TN_COMPANIES ? CTMN_CLIENT_LIST : CTMN_SPECTATOR) : (int)_local_company); @@ -318,24 +318,24 @@ enum OptionMenuEntries { static CallBackFunction ToolbarOptionsClick(Window *w) { DropDownList *list = new DropDownList(); - *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_GAME_OPTIONS, OME_GAMEOPTIONS, false); - *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_CONFIG_SETTINGS_TREE, OME_SETTINGS, false); + list->push_back(new DropDownListStringItem(STR_SETTINGS_MENU_GAME_OPTIONS, OME_GAMEOPTIONS, false)); + list->push_back(new DropDownListStringItem(STR_SETTINGS_MENU_CONFIG_SETTINGS_TREE, OME_SETTINGS, false)); /* Changes to the per-AI settings don't get send from the server to the clients. Clients get * the settings once they join but never update it. As such don't show the window at all * to network clients. */ - if (!_networking || _network_server) *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_SCRIPT_SETTINGS, OME_SCRIPT_SETTINGS, false); - *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_NEWGRF_SETTINGS, OME_NEWGRFSETTINGS, false); - *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS, OME_TRANSPARENCIES, false); - *list->Append() = new DropDownListItem(-1, false); - *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED, OME_SHOW_TOWNNAMES, false, HasBit(_display_opt, DO_SHOW_TOWN_NAMES)); - *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED, OME_SHOW_STATIONNAMES, false, HasBit(_display_opt, DO_SHOW_STATION_NAMES)); - *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED, OME_SHOW_WAYPOINTNAMES, false, HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES)); - *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_SIGNS_DISPLAYED, OME_SHOW_SIGNS, false, HasBit(_display_opt, DO_SHOW_SIGNS)); - *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS, OME_SHOW_COMPETITOR_SIGNS, false, HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)); - *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_ANIMATION, OME_FULL_ANIMATION, false, HasBit(_display_opt, DO_FULL_ANIMATION)); - *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_DETAIL, OME_FULL_DETAILS, false, HasBit(_display_opt, DO_FULL_DETAIL)); - *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS, OME_TRANSPARENTBUILDINGS, false, IsTransparencySet(TO_HOUSES)); - *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_SIGNS, OME_SHOW_STATIONSIGNS, false, IsTransparencySet(TO_SIGNS)); + if (!_networking || _network_server) list->push_back(new DropDownListStringItem(STR_SETTINGS_MENU_SCRIPT_SETTINGS, OME_SCRIPT_SETTINGS, false)); + list->push_back(new DropDownListStringItem(STR_SETTINGS_MENU_NEWGRF_SETTINGS, OME_NEWGRFSETTINGS, false)); + list->push_back(new DropDownListStringItem(STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS, OME_TRANSPARENCIES, false)); + list->push_back(new DropDownListItem(-1, false)); + list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED, OME_SHOW_TOWNNAMES, false, HasBit(_display_opt, DO_SHOW_TOWN_NAMES))); + list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED, OME_SHOW_STATIONNAMES, false, HasBit(_display_opt, DO_SHOW_STATION_NAMES))); + list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED, OME_SHOW_WAYPOINTNAMES, false, HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES))); + list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_SIGNS_DISPLAYED, OME_SHOW_SIGNS, false, HasBit(_display_opt, DO_SHOW_SIGNS))); + list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS, OME_SHOW_COMPETITOR_SIGNS, false, HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS))); + list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_ANIMATION, OME_FULL_ANIMATION, false, HasBit(_display_opt, DO_FULL_ANIMATION))); + list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_DETAIL, OME_FULL_DETAILS, false, HasBit(_display_opt, DO_FULL_DETAIL))); + list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS, OME_TRANSPARENTBUILDINGS, false, IsTransparencySet(TO_HOUSES))); + list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_SIGNS, OME_SHOW_STATIONSIGNS, false, IsTransparencySet(TO_SIGNS))); ShowDropDownList(w, list, 0, WID_TN_SETTINGS, 140, true, true); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); @@ -464,10 +464,10 @@ enum MapMenuEntries { static CallBackFunction ToolbarMapClick(Window *w) { DropDownList *list = new DropDownList(); - *list->Append() = new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false); - *list->Append() = new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false); - *list->Append() = new DropDownListStringItem(STR_MAP_MENU_LINGRAPH_LEGEND, MME_SHOW_LINKGRAPH, false); - *list->Append() = new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false); + list->push_back(new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false)); + list->push_back(new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false)); + list->push_back(new DropDownListStringItem(STR_MAP_MENU_LINGRAPH_LEGEND, MME_SHOW_LINKGRAPH, false)); + list->push_back(new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false)); PopupMainToolbMenu(w, WID_TN_SMALL_MAP, list, 0); return CBF_NONE; } @@ -475,11 +475,11 @@ static CallBackFunction ToolbarMapClick( static CallBackFunction ToolbarScenMapTownDir(Window *w) { DropDownList *list = new DropDownList(); - *list->Append() = new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false); - *list->Append() = new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false); - *list->Append() = new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false); - *list->Append() = new DropDownListStringItem(STR_TOWN_MENU_TOWN_DIRECTORY, MME_SHOW_TOWNDIRECTORY, false); - *list->Append() = new DropDownListStringItem(STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, MME_SHOW_INDUSTRYDIRECTORY, false); + list->push_back(new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false)); + list->push_back(new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false)); + list->push_back(new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false)); + list->push_back(new DropDownListStringItem(STR_TOWN_MENU_TOWN_DIRECTORY, MME_SHOW_TOWNDIRECTORY, false)); + list->push_back(new DropDownListStringItem(STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, MME_SHOW_INDUSTRYDIRECTORY, false)); PopupMainToolbMenu(w, WID_TE_SMALL_MAP, list, 0); return CBF_NONE; } @@ -897,7 +897,7 @@ static CallBackFunction ToolbarBuildRoad DropDownList *list = new DropDownList(); /* Road is always visible and available. */ - *list->Append() = new DropDownListIconItem(SPR_IMG_ROAD_X_DIR, PAL_NONE, STR_ROAD_MENU_ROAD_CONSTRUCTION, ROADTYPE_ROAD, false); + list->push_back(new DropDownListIconItem(SPR_IMG_ROAD_X_DIR, PAL_NONE, STR_ROAD_MENU_ROAD_CONSTRUCTION, ROADTYPE_ROAD, false)); /* Tram is only visible when there will be a tram, and available when that has been introduced. */ Engine *e; @@ -905,7 +905,7 @@ static CallBackFunction ToolbarBuildRoad if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue; if (!HasBit(e->info.misc_flags, EF_ROAD_TRAM)) continue; - *list->Append() = new DropDownListIconItem(SPR_IMG_TRAMWAY_X_DIR, PAL_NONE, STR_ROAD_MENU_TRAM_CONSTRUCTION, ROADTYPE_TRAM, !HasBit(c->avail_roadtypes, ROADTYPE_TRAM)); + list->push_back(new DropDownListIconItem(SPR_IMG_TRAMWAY_X_DIR, PAL_NONE, STR_ROAD_MENU_TRAM_CONSTRUCTION, ROADTYPE_TRAM, !HasBit(c->avail_roadtypes, ROADTYPE_TRAM))); break; } ShowDropDownList(w, list, _last_built_roadtype, WID_TN_ROADS, 140, true, true); diff --git a/src/town_gui.cpp b/src/town_gui.cpp --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -654,7 +654,7 @@ private: const Town *t; FOR_ALL_TOWNS(t) { - *this->towns.Append() = t; + this->towns.push_back(t); } this->towns.shrink_to_fit(); diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -823,7 +823,7 @@ typedef SmallVector TrainLi */ static void MakeTrainBackup(TrainList &list, Train *t) { - for (; t != NULL; t = t->Next()) *list.Append() = t; + for (; t != NULL; t = t->Next()) list.push_back(t); } /** diff --git a/src/train_gui.cpp b/src/train_gui.cpp --- a/src/train_gui.cpp +++ b/src/train_gui.cpp @@ -280,7 +280,8 @@ static void GetCargoSummaryOfArticulated CargoSummaryItem *item = &*std::find(summary->begin(), summary->end(), new_item); if (item == summary->End()) { - item = summary->Append(); + /*C++17: item = &*/ summary->emplace_back(); + item = &summary->back(); item->cargo = new_item.cargo; item->subtype = new_item.subtype; item->capacity = 0; diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -681,9 +681,8 @@ CommandCost CmdBuildTunnel(TileIndex sta * Do this for all tiles (like trees), not only objects. */ ClearedObjectArea *coa = FindClearedObject(end_tile); if (coa == NULL) { - coa = _cleared_object_areas.Append(); - coa->first_tile = end_tile; - coa->area = TileArea(end_tile, 1, 1); + /*C++17: coa = &*/ _cleared_object_areas.push_back({end_tile, TileArea(end_tile, 1, 1)}); + coa = &_cleared_object_areas.back(); } /* Hide the tile from the terraforming command */ diff --git a/src/vehicle.cpp b/src/vehicle.cpp --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2283,9 +2283,7 @@ void Vehicle::GetConsistFreeCapacities(S if (v->cargo_cap == 0) continue; SmallPair *pair = capacities.Find(v->cargo_type); if (pair == capacities.End()) { - pair = capacities.Append(); - pair->first = v->cargo_type; - pair->second = v->cargo_cap - v->cargo.StoredCount(); + capacities.push_back({v->cargo_type, v->cargo_cap - v->cargo.StoredCount()}); } else { pair->second += v->cargo_cap - v->cargo.StoredCount(); } diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -417,11 +417,7 @@ static CommandCost RefitVehicle(Vehicle * - We have to call the refit cost callback with the pre-refit configuration of the chain because we want refit and * autorefit to behave the same, and we need its result for auto_refit_allowed. */ - RefitResult *result = refit_result.Append(); - result->v = v; - result->capacity = amount; - result->mail_capacity = mail_capacity; - result->subtype = actual_subtype; + refit_result.push_back({v, amount, mail_capacity, actual_subtype}); } if (flags & DC_EXEC) { diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -168,13 +168,13 @@ DropDownList *BaseVehicleListWindow::Bui { DropDownList *list = new DropDownList(); - if (show_autoreplace) *list->Append() = new DropDownListStringItem(STR_VEHICLE_LIST_REPLACE_VEHICLES, ADI_REPLACE, false); - *list->Append() = new DropDownListStringItem(STR_VEHICLE_LIST_SEND_FOR_SERVICING, ADI_SERVICE, false); - *list->Append() = new DropDownListStringItem(this->vehicle_depot_name[this->vli.vtype], ADI_DEPOT, false); + if (show_autoreplace) list->push_back(new DropDownListStringItem(STR_VEHICLE_LIST_REPLACE_VEHICLES, ADI_REPLACE, false)); + list->push_back(new DropDownListStringItem(STR_VEHICLE_LIST_SEND_FOR_SERVICING, ADI_SERVICE, false)); + list->push_back(new DropDownListStringItem(this->vehicle_depot_name[this->vli.vtype], ADI_DEPOT, false)); if (show_group) { - *list->Append() = new DropDownListStringItem(STR_GROUP_ADD_SHARED_VEHICLE, ADI_ADD_SHARED, false); - *list->Append() = new DropDownListStringItem(STR_GROUP_REMOVE_ALL_VEHICLES, ADI_REMOVE_ALL, false); + list->push_back(new DropDownListStringItem(STR_GROUP_ADD_SHARED_VEHICLE, ADI_ADD_SHARED, false)); + list->push_back(new DropDownListStringItem(STR_GROUP_REMOVE_ALL_VEHICLES, ADI_REMOVE_ALL, false)); } return list; @@ -438,10 +438,7 @@ struct RefitWindow : public Window { bool first_vehicle = this->list[current_index].size() == 0; if (first_vehicle) { /* Keeping the current subtype is always an option. It also serves as the option in case of no subtypes */ - RefitOption *option = this->list[current_index].Append(); - option->cargo = cid; - option->subtype = 0xFF; - option->string = STR_EMPTY; + this->list[current_index].push_back({cid, 0xFF, STR_EMPTY}); } /* Check the vehicle's callback mask for cargo suffixes. diff --git a/src/vehiclelist.cpp b/src/vehiclelist.cpp --- a/src/vehiclelist.cpp +++ b/src/vehiclelist.cpp @@ -85,7 +85,7 @@ void BuildDepotVehicleList(VehicleType t if (t->IsArticulatedPart() || t->IsRearDualheaded()) continue; if (t->track != TRACK_BIT_DEPOT) continue; if (wagons != NULL && t->First()->IsFreeWagon()) { - if (individual_wagons || t->IsFreeWagon()) *wagons->Append() = t; + if (individual_wagons || t->IsFreeWagon()) wagons->push_back(t); continue; } break; @@ -98,7 +98,7 @@ void BuildDepotVehicleList(VehicleType t if (!v->IsPrimaryVehicle()) continue; - *engines->Append() = v; + engines->push_back(v); } /* Ensure the lists are not wasting too much space. If the lists are fresh @@ -128,7 +128,7 @@ bool GenerateVehicleSortList(VehicleList FOR_VEHICLE_ORDERS(v, order) { if ((order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT) || order->IsType(OT_IMPLICIT)) && order->GetDestination() == vli.index) { - *list->Append() = v; + list->push_back(v); break; } } @@ -142,7 +142,7 @@ bool GenerateVehicleSortList(VehicleList if (v == NULL || v->type != vli.vtype || !v->IsPrimaryVehicle()) return false; for (; v != NULL; v = v->NextShared()) { - *list->Append() = v; + list->push_back(v); } break; @@ -151,7 +151,7 @@ bool GenerateVehicleSortList(VehicleList FOR_ALL_VEHICLES(v) { if (v->type == vli.vtype && v->IsPrimaryVehicle() && v->owner == vli.company && GroupIsInGroup(v->group_id, vli.index)) { - *list->Append() = v; + list->push_back(v); } } break; @@ -161,7 +161,7 @@ bool GenerateVehicleSortList(VehicleList case VL_STANDARD: FOR_ALL_VEHICLES(v) { if (v->type == vli.vtype && v->owner == vli.company && v->IsPrimaryVehicle()) { - *list->Append() = v; + list->push_back(v); } } break; @@ -173,7 +173,7 @@ bool GenerateVehicleSortList(VehicleList FOR_VEHICLE_ORDERS(v, order) { if (order->IsType(OT_GOTO_DEPOT) && !(order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) && order->GetDestination() == vli.index) { - *list->Append() = v; + list->push_back(v); break; } } diff --git a/src/viewport.cpp b/src/viewport.cpp --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -499,13 +499,14 @@ static void AddTileSpriteToDraw(SpriteID { assert((image & SPRITE_MASK) < MAX_SPRITES); - TileSpriteToDraw *ts = _vd.tile_sprites_to_draw.Append(); - ts->image = image; - ts->pal = pal; - ts->sub = sub; + /*C++17: TileSpriteToDraw &ts = */ _vd.tile_sprites_to_draw.emplace_back(); + TileSpriteToDraw &ts = _vd.tile_sprites_to_draw.back(); + ts.image = image; + ts.pal = pal; + ts.sub = sub; Point pt = RemapCoords(x, y, z); - ts->x = pt.x + extra_offs_x; - ts->y = pt.y + extra_offs_y; + ts.x = pt.x + extra_offs_x; + ts.y = pt.y + extra_offs_y; } /** @@ -708,29 +709,30 @@ void AddSortableSpriteToDraw(SpriteID im return; } - ParentSpriteToDraw *ps = _vd.parent_sprites_to_draw.Append(); - ps->x = tmp_x; - ps->y = tmp_y; - - ps->left = tmp_left; - ps->top = tmp_top; - - ps->image = image; - ps->pal = pal; - ps->sub = sub; - ps->xmin = x + bb_offset_x; - ps->xmax = x + max(bb_offset_x, w) - 1; - - ps->ymin = y + bb_offset_y; - ps->ymax = y + max(bb_offset_y, h) - 1; - - ps->zmin = z + bb_offset_z; - ps->zmax = z + max(bb_offset_z, dz) - 1; - - ps->comparison_done = false; - ps->first_child = -1; - - _vd.last_child = &ps->first_child; + /*C++17: ParentSpriteToDraw &ps = */ _vd.parent_sprites_to_draw.emplace_back(); + ParentSpriteToDraw &ps = _vd.parent_sprites_to_draw.back(); + ps.x = tmp_x; + ps.y = tmp_y; + + ps.left = tmp_left; + ps.top = tmp_top; + + ps.image = image; + ps.pal = pal; + ps.sub = sub; + ps.xmin = x + bb_offset_x; + ps.xmax = x + max(bb_offset_x, w) - 1; + + ps.ymin = y + bb_offset_y; + ps.ymax = y + max(bb_offset_y, h) - 1; + + ps.zmin = z + bb_offset_z; + ps.zmax = z + max(bb_offset_z, dz) - 1; + + ps.comparison_done = false; + ps.first_child = -1; + + _vd.last_child = &ps.first_child; if (_vd.combine_sprites == SPRITE_COMBINE_PENDING) _vd.combine_sprites = SPRITE_COMBINE_ACTIVE; } @@ -826,33 +828,35 @@ void AddChildSpriteScreen(SpriteID image *_vd.last_child = _vd.child_screen_sprites_to_draw.size(); - ChildScreenSpriteToDraw *cs = _vd.child_screen_sprites_to_draw.Append(); - cs->image = image; - cs->pal = pal; - cs->sub = sub; - cs->x = scale ? x * ZOOM_LVL_BASE : x; - cs->y = scale ? y * ZOOM_LVL_BASE : y; - cs->next = -1; + /*C++17: ChildScreenSpriteToDraw &cs = */ _vd.child_screen_sprites_to_draw.emplace_back(); + ChildScreenSpriteToDraw &cs = _vd.child_screen_sprites_to_draw.back(); + cs.image = image; + cs.pal = pal; + cs.sub = sub; + cs.x = scale ? x * ZOOM_LVL_BASE : x; + cs.y = scale ? y * ZOOM_LVL_BASE : y; + cs.next = -1; /* Append the sprite to the active ChildSprite list. * If the active ParentSprite is a foundation, update last_foundation_child as well. * Note: ChildSprites of foundations are NOT sequential in the vector, as selection sprites are added at last. */ - if (_vd.last_foundation_child[0] == _vd.last_child) _vd.last_foundation_child[0] = &cs->next; - if (_vd.last_foundation_child[1] == _vd.last_child) _vd.last_foundation_child[1] = &cs->next; - _vd.last_child = &cs->next; + if (_vd.last_foundation_child[0] == _vd.last_child) _vd.last_foundation_child[0] = &cs.next; + if (_vd.last_foundation_child[1] == _vd.last_child) _vd.last_foundation_child[1] = &cs.next; + _vd.last_child = &cs.next; } static void AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2, Colours colour, uint16 width) { assert(width != 0); - StringSpriteToDraw *ss = _vd.string_sprites_to_draw.Append(); - ss->string = string; - ss->x = x; - ss->y = y; - ss->params[0] = params_1; - ss->params[1] = params_2; - ss->width = width; - ss->colour = colour; + /*C++17: StringSpriteToDraw &ss = */ _vd.string_sprites_to_draw.emplace_back(); + StringSpriteToDraw &ss = _vd.string_sprites_to_draw.back(); + ss.string = string; + ss.x = x; + ss.y = y; + ss.params[0] = params_1; + ss.params[1] = params_2; + ss.width = width; + ss.colour = colour; } @@ -1588,7 +1592,7 @@ void ViewportDoDraw(const ViewPort *vp, ParentSpriteToDraw *psd_end = _vd.parent_sprites_to_draw.End(); for (ParentSpriteToDraw *it = _vd.parent_sprites_to_draw.Begin(); it != psd_end; it++) { - *_vd.parent_sprites_to_sort.Append() = it; + _vd.parent_sprites_to_sort.push_back(it); } _vp_sprite_sorter(&_vd.parent_sprites_to_sort); diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -509,7 +509,7 @@ void ShowDropDownMenu(Window *w, const S for (uint i = 0; strings[i] != INVALID_STRING_ID; i++) { if (!HasBit(hidden_mask, i)) { - *list->Append() = new DropDownListStringItem(strings[i], i, HasBit(disabled_mask, i)); + list->push_back(new DropDownListStringItem(strings[i], i, HasBit(disabled_mask, i))); } } diff --git a/src/window.cpp b/src/window.cpp --- a/src/window.cpp +++ b/src/window.cpp @@ -109,7 +109,7 @@ WindowDesc::WindowDesc(WindowPosition de default_height_trad(def_height_trad) { if (_window_descs == NULL) _window_descs = new SmallVector(); - *_window_descs->Append() = this; + _window_descs->push_back(this); } WindowDesc::~WindowDesc() @@ -3242,7 +3242,7 @@ void Window::InvalidateData(int data, bo this->SetDirty(); if (!gui_scope) { /* Schedule GUI-scope invalidation for next redraw. */ - *this->scheduled_invalidation_data.Append() = data; + this->scheduled_invalidation_data.push_back(data); } this->OnInvalidateData(data, gui_scope); }