Deployed more emplace_back (how do I keep missing these...)

Covers more cases of:

* push_back(std::pair
* push_back(std::make_pair
* push_back(std::make_tuple
* push_back(T) where T is an empty object of type T

Small thing I noticed: this does mean the numbers in font::subset_descriptor are no longer 'cast' to size_t before being
added to the vector, but that shouldn't matter (hopefully).
This commit is contained in:
Charles Dang 2017-04-28 17:15:13 +11:00
parent ac23b4579e
commit 2a6ca6cd9e
19 changed files with 51 additions and 60 deletions

View File

@ -282,7 +282,7 @@ void configuration::expand_simplified_aspects(side_number side, config &cfg) {
facet_config["turns"] = turns;
facet_config["time_of_day"] = time_of_day;
facet_config["value"] = attr.second;
facet_configs.push_back(std::make_pair(attr.first, facet_config));
facet_configs.emplace_back(attr.first, facet_config);
}
for (const config::any_child &child : aiparam.all_children_range()) {
if (just_copy_tags.count(child.key)) {
@ -310,7 +310,7 @@ void configuration::expand_simplified_aspects(side_number side, config &cfg) {
// then it can be copied verbatim as a [facet] tag.
// Otherwise, it needs to be placed as a [value] within a [facet] tag.
if (child.key == "attacks" || child.cfg.has_attribute("value") || child.cfg.has_child("value")) {
facet_configs.push_back(std::make_pair(child.key, child.cfg));
facet_configs.emplace_back(child.key, child.cfg);
} else {
config facet_config;
facet_config["engine"] = engine;
@ -325,7 +325,7 @@ void configuration::expand_simplified_aspects(side_number side, config &cfg) {
facet_config["id"] = child.cfg["id"];
}
}
facet_configs.push_back(std::make_pair(child.key, facet_config));
facet_configs.emplace_back(child.key, facet_config);
}
}
std::map<std::string, config> aspect_configs;

View File

@ -322,7 +322,7 @@ void aspect_attacks_base::do_attack_analysis(
if(cur_position != -1) {
units.erase(units.begin() + i);
cur_analysis.movements.push_back(std::pair<map_location,map_location>(current_unit,tiles[cur_position]));
cur_analysis.movements.emplace_back(current_unit,tiles[cur_position]);
cur_analysis.vulnerability += best_vulnerability;

View File

@ -752,7 +752,7 @@ void get_villages_phase::find_villages(
move_result_ptr move_check_res = check_move_action(j->second,j->first,true);
if (move_check_res->is_ok()) {
DBG_AI_TESTING_AI_DEFAULT << "Dispatched unit at " << j->second << " to village " << j->first << '\n';
moves.push_back(std::make_pair(j->first, j->second));
moves.emplace_back(j->first, j->second);
}
reachmap.erase(j->second);
dispatched_units.push_back(j->second);
@ -837,7 +837,7 @@ bool get_villages_phase::dispatch_unit_simple(treachmap& reachmap, tmoves& moves
result = true;
DBG_AI_TESTING_AI_DEFAULT << "Dispatched unit at " << itor->first << " to village " << village << '\n';
moves.push_back(std::make_pair(village, itor->first));
moves.emplace_back(village, itor->first);
reachmap.erase(itor++);
if(remove_village(reachmap, moves, village)) {
@ -860,8 +860,7 @@ bool get_villages_phase::dispatch_unit_simple(treachmap& reachmap, tmoves& moves
DBG_AI_TESTING_AI_DEFAULT << "Dispatched _last_ unit at " << reachmap.begin()->first
<< " to village " << reachmap.begin()->second[0] << '\n';
moves.push_back(std::make_pair(
reachmap.begin()->second[0], reachmap.begin()->first));
moves.emplace_back(reachmap.begin()->second[0], reachmap.begin()->first);
reachmap.clear();
// We're done.
@ -907,7 +906,7 @@ bool get_villages_phase::dispatch_village_simple(
result = true;
DBG_AI_TESTING_AI_DEFAULT << "Dispatched unit at " << itor->second[0] << " to village " << itor->first << '\n';
moves.push_back(std::make_pair(itor->first, itor->second[0]));
moves.emplace_back(itor->first, itor->second[0]);
reachmap.erase(itor->second[0]);
remove_village(reachmap, moves, village);
@ -949,7 +948,7 @@ get_villages_phase::treachmap::iterator get_villages_phase::remove_unit(
DBG_AI_TESTING_AI_DEFAULT << "Dispatch leader at " << leader_loc_ << " closer to the keep at "
<< best_leader_loc_ << '\n';
moves.push_back(std::make_pair(best_leader_loc_, leader_loc_));
moves.emplace_back(best_leader_loc_, leader_loc_);
}
reachmap.erase(unit++);
@ -1092,11 +1091,11 @@ void get_villages_phase::dispatch_complex(
// Dispatch
DBG_AI_TESTING_AI_DEFAULT << "Found a square.\nDispatched unit at " << units[src_itor->second]
<< " to village " << village1 << '\n';
moves.push_back(std::make_pair(village1, units[src_itor->second]));
moves.emplace_back(village1, units[src_itor->second]);
DBG_AI_TESTING_AI_DEFAULT << "Dispatched unit at " << units[dst_itor->second]
<< " to village " << village2 << '\n';
moves.push_back(std::make_pair(village2, units[dst_itor->second]));
moves.emplace_back(village2, units[dst_itor->second]);
// Remove the units
reachmap.erase(units[src_itor->second]);
@ -1157,7 +1156,7 @@ void get_villages_phase::dispatch_complex(
std::vector<std::pair<map_location,map_location> > result;
for(size_t u = 0; u < max_options; ++u) {
if(matrix[u][perm[u]]) {
result.push_back(std::make_pair(villages[perm[u]], units[u]));
result.emplace_back(villages[perm[u]], units[u]);
}
}
@ -1195,7 +1194,7 @@ void get_villages_phase::dispatch_complex(
std::vector<std::pair<map_location,map_location> > result;
for(size_t u = 0; u < unit_count; ++u) {
if(matrix[u][perm[u]]) {
result.push_back(std::make_pair(villages[perm[u]], units[u]));
result.emplace_back(villages[perm[u]], units[u]);
}
}
@ -1237,7 +1236,7 @@ void get_villages_phase::dispatch_complex(
std::vector<std::pair<map_location,map_location> > result;
for(size_t v = 0; v < village_count; ++v) {
if(matrix[perm[v]][v]) {
result.push_back(std::make_pair(villages[v], units[perm[v]]));
result.emplace_back(villages[v], units[perm[v]]);
}
}
@ -1274,7 +1273,7 @@ void get_villages_phase::full_dispatch(treachmap& reachmap, tmoves& moves)
for(size_t i = 0; i < reachmap.size(); ++i, ++itor) {
DBG_AI_TESTING_AI_DEFAULT << "Dispatched unit at " << itor->first
<< " to village " << itor->second[i] << '\n';
moves.push_back(std::make_pair(itor->second[i], itor->first));
moves.emplace_back(itor->second[i], itor->first);
}
}

View File

@ -928,7 +928,7 @@ void recruitment::do_combat_analysis(std::vector<data>* leader_data) {
if (!current_team().is_enemy(unit.side()) || unit.incapacitated()) {
continue;
}
enemy_units.push_back(std::make_pair(unit.type_id(), unit.hitpoints()));
enemy_units.emplace_back(unit.type_id(), unit.hitpoints());
}
if (enemy_units.size() < UNIT_THRESHOLD) {
// Use also enemies recruitment lists and insert units into enemy_units.
@ -949,7 +949,7 @@ void recruitment::do_combat_analysis(std::vector<data>* leader_data) {
const unit_type* recruit_type = unit_types.find(possible_recruit);
if (recruit_type) {
int hp = recruit_type->hitpoints();
enemy_units.push_back(std::make_pair(possible_recruit, hp));
enemy_units.emplace_back(possible_recruit, hp);
}
}
}

View File

@ -479,7 +479,7 @@ void commandline_options::parse_log_domains_(const std::string &domains_string,
{
if (!log)
log = std::vector<std::pair<int, std::string> >();
log->push_back(std::make_pair(severity, domain));
log->emplace_back(severity, domain);
}
}
@ -534,7 +534,7 @@ std::vector<std::pair<unsigned int,std::string> > commandline_options::parse_to_
throw bad_commandline_tuple(s, expected_format);
}
vec.push_back(std::make_pair(temp, tokens[1]));
vec.emplace_back(temp, tokens[1]);
}
return vec;
}

View File

@ -39,7 +39,7 @@ struct configr_of
configr_of& operator()(const std::string& tagname, const configr_of& child)
{
subtags_.push_back(std::make_pair(&tagname, &child));
subtags_.emplace_back(&tagname, &child);
return *this;
}
std::vector<std::pair<const std::string*, const configr_of*>> subtags_;

View File

@ -60,12 +60,12 @@ struct subset_descriptor
std::vector<std::string> r = utils::split(i, '-');
if(r.size() == 1) {
size_t r1 = lexical_cast_default<size_t>(r[0], 0);
present_codepoints.push_back(std::pair<size_t, size_t>(r1, r1));
present_codepoints.emplace_back(r1, r1);
} else if(r.size() == 2) {
size_t r1 = lexical_cast_default<size_t>(r[0], 0);
size_t r2 = lexical_cast_default<size_t>(r[1], 0);
present_codepoints.push_back(std::pair<size_t, size_t>(r1, r2));
present_codepoints.emplace_back(r1, r2);
}
}
}

View File

@ -1376,7 +1376,7 @@ void side_engine::add_controller_option(ng::controller controller,
return;
}
controller_options_.push_back(std::make_pair(controller, name));
controller_options_.emplace_back(controller, name);
}
} // end namespace ng

View File

@ -1488,7 +1488,7 @@ unsigned image_width(const std::string &filename)
void push_tab_pair(std::vector<std::pair<std::string, unsigned int> > &v, const std::string &s)
{
v.push_back(std::make_pair(s, font::line_width(s, normal_font_size)));
v.emplace_back(s, font::line_width(s, normal_font_size));
}
std::string generate_table(const table_spec &tab, const unsigned int spacing)

View File

@ -401,7 +401,7 @@ std::string unit_topic_generator::operator()() const {
continue;
}
const std::string ref_id = "traits_"+trait["id"].str();
((trait["availability"].str() == "musthave") ? must_have_traits : random_traits).push_back(std::make_pair(lang_trait_name, ref_id));
((trait["availability"].str() == "musthave") ? must_have_traits : random_traits).emplace_back(lang_trait_name, ref_id);
}
bool line1 = !must_have_traits.empty();
@ -515,7 +515,7 @@ std::string unit_topic_generator::operator()() const {
std::vector<item> row;
std::stringstream attack_ss;
attack_ss << "<img>src='" << attack.icon() << "'</img>";
row.push_back(std::make_pair(attack_ss.str(),image_width(attack.icon())));
row.emplace_back(attack_ss.str(),image_width(attack.icon()));
push_tab_pair(row, lang_weapon);
push_tab_pair(row, lang_type);
attack_ss.str(clear_stringstream);
@ -544,8 +544,7 @@ std::string unit_topic_generator::operator()() const {
attack_ss << ", "; //comma placed before next special
}
}
row.push_back(std::make_pair(attack_ss.str(),
font::line_width(lang_special, normal_font_size)));
row.emplace_back(attack_ss.str(), font::line_width(lang_special, normal_font_size));
}
table.push_back(row);
}
@ -596,8 +595,7 @@ std::string unit_topic_generator::operator()() const {
const std::string markup = str.str();
str.str(clear_stringstream);
str << resist;
row.push_back(std::make_pair(markup,
font::line_width(str.str(), normal_font_size)));
row.emplace_back(markup, font::line_width(str.str(), normal_font_size));
resistance_table.push_back(row);
}
ss << generate_table(resistance_table);
@ -652,9 +650,9 @@ std::string unit_topic_generator::operator()() const {
const std::string final_image = tc_base + "~RC(magenta>" + id + ")~BLIT(" + terrain_image + ")";
row.push_back(std::make_pair( "<img>src='" + final_image + "'</img> " +
row.emplace_back("<img>src='" + final_image + "'</img> " +
make_link(name, "..terrain_" + id),
font::line_width(name, normal_font_size) + (high_res ? 32 : 16) ));
font::line_width(name, normal_font_size) + (high_res ? 32 : 16) );
//defense - range: +10 % .. +70 %
const int defense = 100 - movement_type.defense_modifier(terrain);
@ -674,8 +672,7 @@ std::string unit_topic_generator::operator()() const {
std::string markup = str.str();
str.str(clear_stringstream);
str << defense << "%";
row.push_back(std::make_pair(markup,
font::line_width(str.str(), normal_font_size)));
row.emplace_back(markup, font::line_width(str.str(), normal_font_size));
//movement - range: 1 .. 5, movetype::UNREACHABLE=impassable
str.str(clear_stringstream);
@ -699,8 +696,7 @@ std::string unit_topic_generator::operator()() const {
markup = str.str();
str.str(clear_stringstream);
str << moves;
row.push_back(std::make_pair(markup,
font::line_width(str.str(), normal_font_size)));
row.emplace_back(markup, font::line_width(str.str(), normal_font_size));
//defense cap
if (has_terrain_defense_caps) {
@ -718,8 +714,7 @@ std::string unit_topic_generator::operator()() const {
} else {
str << font::unicode_figure_dash;
}
row.push_back(std::make_pair(markup,
font::line_width(str.str(), normal_font_size)));
row.emplace_back(markup, font::line_width(str.str(), normal_font_size));
}
//vision
@ -747,8 +742,7 @@ std::string unit_topic_generator::operator()() const {
markup = str.str();
str.str(clear_stringstream);
str << views;
row.push_back(std::make_pair(markup,
font::line_width(str.str(), normal_font_size)));
row.emplace_back(markup, font::line_width(str.str(), normal_font_size));
}
//jamming

View File

@ -919,7 +919,7 @@ static config unit_weapons(reports::context & rc, const unit *attacker, const ma
// We keep only values above 0.1%.
if(prob > 0.001)
prob_hp_vector.push_back(std::pair<double, int>(prob, i));
prob_hp_vector.emplace_back(prob, i);
}
std::sort(prob_hp_vector.begin(), prob_hp_vector.end());
@ -933,8 +933,7 @@ static config unit_weapons(reports::context & rc, const unit *attacker, const ma
for(i = prob_hp_vector.size() - nb_elem;
i < static_cast<int>(prob_hp_vector.size()); i++) {
hp_prob_vector.push_back(std::pair<int, double>
(prob_hp_vector[i].second, prob_hp_vector[i].first));
hp_prob_vector.emplace_back(prob_hp_vector[i].second, prob_hp_vector[i].first);
}
// Then, we sort the hitpoint values in ascending order.

View File

@ -335,7 +335,7 @@ application_lua_kernel::request_list application_lua_kernel::thread::run_script(
for (const plugins_manager::event & req : this_context_backend->requests) {
results.push_back(std::bind(ctxt.callbacks_.find(req.name)->second, req.data));
//results.push_back(std::make_pair(ctxt.callbacks_.find(req.name)->second, req.data));
//results.emplace_back(ctxt.callbacks_.find(req.name)->second, req.data);
}
return results;
}

View File

@ -692,7 +692,7 @@ void preprocessor_data::pop_token()
prepare for it. */
if (inner_type == token_desc::MACRO_SPACE || inner_type == token_desc::MACRO_CHUNK) {
strings_.erase(strings_.begin() + stack_pos, strings_.end());
strings_.push_back(std::string());
strings_.emplace_back();
}
assert(stack_pos + 1 == strings_.size());
outer_type = token_desc::MACRO_CHUNK;

View File

@ -170,7 +170,7 @@ void terrain_builder::tile::rebuild_cache(const std::string& tod, logs* log)
}
if(log) {
log->push_back(std::make_pair(&ri, &variant));
log->emplace_back(&ri, &variant);
}
break; // found a matching variant

View File

@ -265,10 +265,10 @@ std::vector<std::tuple<t_string, t_string, t_string> > unit::ability_tooltips(bo
gender_value(ab.cfg, gender_, "name", "female_name", "name").t_str();
if (!name.empty()) {
res.push_back(std::make_tuple(
res.emplace_back(
ab.cfg["name"].t_str(),
name,
ab.cfg["description"].t_str() ));
ab.cfg["description"].t_str() );
if ( active_list )
active_list->push_back(true);
}
@ -283,10 +283,10 @@ std::vector<std::tuple<t_string, t_string, t_string> > unit::ability_tooltips(bo
gender_value(ab.cfg, gender_, "name", "female_name", "name").t_str();
if (!name.empty()) {
res.push_back(std::make_tuple(
res.emplace_back(
default_value(ab.cfg, "name_inactive", "name").t_str(),
name,
default_value(ab.cfg, "description_inactive", "description").t_str() ));
default_value(ab.cfg, "description_inactive", "description").t_str() );
active_list->push_back(false);
}
}
@ -615,15 +615,14 @@ std::vector<std::pair<t_string, t_string> > attack_type::special_tooltips(
if ( !active_list || special_active(sp.cfg, AFFECT_EITHER) ) {
const t_string &name = sp.cfg["name"];
if (!name.empty()) {
res.push_back(std::make_pair(name, sp.cfg["description"].t_str() ));
res.emplace_back(name, sp.cfg["description"].t_str() );
if ( active_list )
active_list->push_back(true);
}
} else {
t_string const &name = default_value(sp.cfg, "name_inactive", "name").t_str();
if (!name.empty()) {
res.push_back(std::make_pair(
name, default_value(sp.cfg, "description_inactive", "description").t_str() ));
res.emplace_back(name, default_value(sp.cfg, "description_inactive", "description").t_str() );
active_list->push_back(false);
}
}

View File

@ -1218,8 +1218,8 @@ void unit_type_data::read_hide_help(const config& cfg)
if (!cfg)
return;
hide_help_race_.push_back(std::set<std::string>());
hide_help_type_.push_back(std::set<std::string>());
hide_help_race_.emplace_back();
hide_help_type_.emplace_back();
std::vector<std::string> races = utils::split(cfg["race"]);
hide_help_race_.back().insert(races.begin(), races.end());

View File

@ -47,7 +47,7 @@ context_free_grammar_generator::context_free_grammar_generator(const std::string
throw name_generator_invalid_exception("[context_free_grammar_generator] Parsing error: nonterminals (, ! and ) may not be overridden");
}
current = &nonterminals_[key];
current->possibilities_.push_back(std::vector<std::string>());
current->possibilities_.emplace_back();
filled = &current->possibilities_.back();
buf.clear();
} else if (*reading == '\n') {
@ -61,7 +61,7 @@ context_free_grammar_generator::context_free_grammar_generator(const std::string
throw name_generator_invalid_exception("[context_free_grammar_generator] Parsing error: misplaced | symbol");
}
filled->push_back(buf);
current->possibilities_.push_back(std::vector<std::string>());
current->possibilities_.emplace_back();
filled = &current->possibilities_.back();
buf.clear();
} else if (*reading == '\\' && reading[1] == 'n') {

View File

@ -353,7 +353,7 @@ std::vector<std::pair<int, int>> CVideo::get_available_resolutions(const bool in
for (int i = 0; i < modes; ++i) {
if(SDL_GetDisplayMode(0, i, &mode) == 0) {
if(mode.w >= min_res.first && mode.h >= min_res.second)
result.push_back(std::make_pair(mode.w, mode.h));
result.emplace_back(mode.w, mode.h);
}
}

View File

@ -876,7 +876,7 @@ static std::vector<std::string> parse_commandline_arguments(std::string input)
while(parse_commandline_argument(start, end, buffer))
{
res.push_back(std::string());
res.emplace_back();
res.back().swap(buffer);
}
return res;