← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/auto-pairs into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/auto-pairs into lp:widelands.

Commit message:
Using auto for more efficient iterating over maps.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/auto-pairs/+merge/288654

Thanks to the Scott Meyers book that SirVer recommended to me, here's a bit of efficiency gain.

When iterating over maps, the key component of the pair should always be const - otherwise, unnecessary copies will be created. One tends to forget (and we did - a lot), so using auto is a good thing - also less of a headache when small changes to the map's datatypes are made.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/auto-pairs into lp:widelands.
=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc	2016-03-02 17:13:06 +0000
+++ src/ai/defaultai.cc	2016-03-10 14:42:34 +0000
@@ -577,7 +577,7 @@
 		if (bld.type() == MapObjectType::PRODUCTIONSITE) {
 			const ProductionSiteDescr& prod = dynamic_cast<const ProductionSiteDescr&>(bld);
 			bo.type = bld.get_ismine() ? BuildingObserver::Type::kMine : BuildingObserver::Type::kProductionsite;
-			for (const WareAmount& temp_input : prod.inputs()) {
+			for (const auto& temp_input : prod.inputs()) {
 				bo.inputs.push_back(temp_input.first);
 			}
 			for (const DescriptionIndex& temp_output : prod.output_ware_types()) {
@@ -671,7 +671,7 @@
 		if (bld.type() == MapObjectType::MILITARYSITE) {
 			bo.type = BuildingObserver::Type::kMilitarysite;
 			const MilitarySiteDescr& milit = dynamic_cast<const MilitarySiteDescr&>(bld);
-			for (const std::pair<unsigned char, unsigned char>& temp_buildcosts : milit.buildcost()) {
+			for (const auto& temp_buildcosts : milit.buildcost()) {
 				// bellow are non-critical wares (well, various types of wood)
 				if (tribe_->ware_index("log") == temp_buildcosts.first ||
 				    tribe_->ware_index("blackwood") == temp_buildcosts.first ||
@@ -691,7 +691,7 @@
 		if (bld.type() == MapObjectType::TRAININGSITE) {
 			bo.type = BuildingObserver::Type::kTrainingsite;
 			const TrainingSiteDescr& train = dynamic_cast<const TrainingSiteDescr&>(bld);
-			for (const WareAmount& temp_input : train.inputs()) {
+			for (const auto& temp_input : train.inputs()) {
 				bo.inputs.push_back(temp_input.first);
 
 				// collecting subsitutes
@@ -702,7 +702,7 @@
 					bo.substitute_inputs.insert(temp_input.first);
 				}
 
-				for (const std::pair<unsigned char, unsigned char>& temp_buildcosts : train.buildcost()) {
+				for (const auto& temp_buildcosts : train.buildcost()) {
 					// critical wares for trainingsites
 					if (tribe_->ware_index("spidercloth") == temp_buildcosts.first ||
 						tribe_->ware_index("gold") == temp_buildcosts.first ||
@@ -3110,7 +3110,7 @@
 	// Get max radius of recursive workarea
 	WorkareaInfo::size_type radius = 0;
 	const WorkareaInfo& workarea_info = site.bo->desc->workarea_info_;
-	for (const std::pair<uint32_t, std::set<std::string>>& temp_info : workarea_info) {
+	for (const auto& temp_info : workarea_info) {
 		if (radius < temp_info.first) {
 			radius = temp_info.first;
 		}
@@ -5884,7 +5884,7 @@
 // all levels)
 uint32_t DefaultAI::mines_in_constr() const {
 	uint32_t count = 0;
-	for (const std::pair<const int, MineTypesObserver> m : mines_per_type) {
+	for (const auto& m : mines_per_type) {
 		count += m.second.in_construction;
 	}
 	return count;
@@ -5892,7 +5892,7 @@
 
 uint32_t DefaultAI::mines_built() const{
 	uint32_t count = 0;
-	for (const std::pair<const int, MineTypesObserver> m : mines_per_type) {
+	for (const auto& m : mines_per_type) {
 		count += m.second.finished;
 	}
 	return count;
@@ -5901,14 +5901,14 @@
 // following two functions count militarysites of the same size
 uint32_t DefaultAI::msites_in_constr() const {
 	uint32_t count = 0;
-	for (const std::pair<const int, MilitarySiteSizeObserver> m : msites_per_size) {
+	for (const auto& m : msites_per_size) {
 		count += m.second.in_construction;
 	}
 	return count;
 }
 uint32_t DefaultAI::msites_built() const{
 	uint32_t count = 0;
-	for (const std::pair<const int, MilitarySiteSizeObserver> m : msites_per_size) {
+	for (const auto& m : msites_per_size) {
 		count += m.second.finished;
 	}
 	return count;

=== modified file 'src/economy/economy.cc'
--- src/economy/economy.cc	2016-02-09 16:29:48 +0000
+++ src/economy/economy.cc	2016-03-10 14:42:34 +0000
@@ -957,7 +957,7 @@
 	uint32_t idx = 0;
 	uint32_t scarcest_idx = 0;
 	bool plan_at_least_one = false;
-	for (const std::pair<std::string, uint8_t>& bc : cost) {
+	for (const auto& bc : cost) {
 		uint32_t cc = total_available[idx] / bc.second;
 		if (cc <= can_create) {
 			scarcest_idx = idx;
@@ -1136,7 +1136,7 @@
 	ss.unsigned_32(0x02decafa); // appears as facade02 in sync stream
 	ss.unsigned_32(assignments.size());
 
-	for (const std::pair<Supply *, Warehouse *>& temp_assignment : assignments) {
+	for (const auto& temp_assignment : assignments) {
 		ss.unsigned_32(temp_assignment.first->get_position(game)->serial());
 		ss.unsigned_32(temp_assignment.second->serial());
 

=== modified file 'src/economy/fleet.cc'
--- src/economy/fleet.cc	2016-02-18 08:42:46 +0000
+++ src/economy/fleet.cc	2016-03-10 14:42:34 +0000
@@ -775,7 +775,7 @@
 	}
 
 	//now adding score for distance
-	for (std::pair<std::pair<uint16_t, uint16_t>, uint16_t> ship_port_relation : scores) {
+	for (auto ship_port_relation : scores) {
 
 		// here we get distance ship->port
 		// possibilities are:
@@ -828,7 +828,7 @@
 		best_score = 0;
 
 		// searching for combination with highest score
-		for (std::pair<std::pair<uint16_t, uint16_t>, uint16_t> combination : scores) {
+		for (const auto& combination : scores) {
 			if (combination.second > best_score) {
 				best_score = combination.second;
 				best_ship = combination.first.first;

=== modified file 'src/editor/ui_menus/editor_main_menu_map_options.cc'
--- src/editor/ui_menus/editor_main_menu_map_options.cc	2016-02-17 08:48:02 +0000
+++ src/editor/ui_menus/editor_main_menu_map_options.cc	2016-03-10 14:42:34 +0000
@@ -178,7 +178,7 @@
 	hint_->set_text(map.get_hint());
 
 	std::set<std::string> tags = map.get_tags();
-	for (std::pair<std::string, UI::Checkbox*> tag : tags_checkboxes_) {
+	for (auto tag : tags_checkboxes_) {
 		tag.second->set_state(tags.count(tag.first) > 0);
 	}
 }
@@ -199,7 +199,7 @@
 	eia().egbase().map().set_hint(hint_->get_text());
 
 	eia().egbase().map().clear_tags();
-	for (std::pair<std::string, UI::Checkbox*> tag : tags_checkboxes_) {
+	for (const auto& tag : tags_checkboxes_) {
 		if (tag.second->get_state()) {
 			eia().egbase().map().add_tag(tag.first);
 		}

=== modified file 'src/game_io/game_loader.cc'
--- src/game_io/game_loader.cc	2016-03-05 19:09:10 +0000
+++ src/game_io/game_loader.cc	2016-03-10 14:42:34 +0000
@@ -103,7 +103,7 @@
 	PlayerNumber const nr_players = game_.map().get_nrplayers();
 	iterate_players_existing_const(p, nr_players, game_, player) {
 		const MessageQueue & messages = player->messages();
-		for (std::pair<MessageId, Message *> temp_message : messages) {
+		for (const auto& temp_message : messages) {
 			Message* message = temp_message.second;
 			MessageId message_id = temp_message.first;
 

=== modified file 'src/logic/map_objects/map_object.cc'
--- src/logic/map_objects/map_object.cc	2016-02-17 22:13:21 +0000
+++ src/logic/map_objects/map_object.cc	2016-03-10 14:42:34 +0000
@@ -193,7 +193,7 @@
 std::vector<Serial> ObjectManager::all_object_serials_ordered () const {
 	std::vector<Serial> rv;
 
-	for (const std::pair<Serial, MapObject *>& o : objects_) {
+	for (const auto& o : objects_) {
 		rv.push_back(o.first);
 	}
 
@@ -299,7 +299,7 @@
 
 std::string MapObjectDescr::get_animation_name(uint32_t const anim) const {
 
-	for (const std::pair<std::string, uint32_t>& temp_anim : anims_) {
+	for (const auto& temp_anim : anims_) {
 		if (temp_anim.second == anim) {
 			return temp_anim.first;
 		}

=== modified file 'src/logic/map_objects/tribes/building.cc'
--- src/logic/map_objects/tribes/building.cc	2016-02-22 15:50:39 +0000
+++ src/logic/map_objects/tribes/building.cc	2016-03-10 14:42:34 +0000
@@ -121,7 +121,7 @@
 			//  Merge the enhancements workarea info into this building's
 			//  workarea info.
 			const BuildingDescr * tmp_enhancement = egbase_.tribes().get_building_descr(en_i);
-			for (std::pair<uint32_t, std::set<std::string>> area : tmp_enhancement->workarea_info_)
+			for (auto area : tmp_enhancement->workarea_info_)
 			{
 				std::set<std::string> & strs = workarea_info_[area.first];
 				for (std::string str : area.second)

=== modified file 'src/logic/map_objects/tribes/production_program.cc'
--- src/logic/map_objects/tribes/production_program.cc	2016-03-02 17:13:06 +0000
+++ src/logic/map_objects/tribes/production_program.cc	2016-03-10 14:42:34 +0000
@@ -719,7 +719,7 @@
 		const WorkareaInfo & worker_workarea_info =
 			main_worker_descr.get_program(program_)->get_workarea_info();
 
-		for (const std::pair<uint32_t, std::set<std::string> >& area_info : worker_workarea_info) {
+		for (const auto& area_info : worker_workarea_info) {
 			std::set<std::string> & building_radius_infos =
 				descr->workarea_info_[area_info.first];
 
@@ -922,7 +922,7 @@
 		const TribeDescr & tribe = ps.owner().tribe();
 
 		std::vector<std::string> group_list;
-		for (const WareTypeGroup& group : l_groups) {
+		for (const auto& group : l_groups) {
 			assert(group.first.size());
 
 			std::vector<std::string> ware_list;
@@ -1788,11 +1788,11 @@
 		}
 
 		const ProductionProgram::Action& action = *actions_.back().get();
-		for (const WareTypeGroup& group : action.consumed_wares()) {
+		for (const auto& group : action.consumed_wares()) {
 			consumed_wares_.push_back(group);
 		}
 		// Add produced wares. If the ware already exists, increase the amount
-		for (const WareAmount& ware : action.produced_wares()) {
+		for (const auto& ware : action.produced_wares()) {
 			if (produced_wares_.count(ware.first) == 1) {
 				produced_wares_.at(ware.first) += ware.second;
 			} else {
@@ -1800,7 +1800,7 @@
 			}
 		}
 		// Add recruited workers. If the worker already exists, increase the amount
-		for (const WareAmount& worker : action.recruited_workers()) {
+		for (const auto& worker : action.recruited_workers()) {
 			if (recruited_workers_.count(worker.first) == 1) {
 				recruited_workers_.at(worker.first) += worker.second;
 			} else {

=== modified file 'src/logic/map_objects/tribes/productionsite.cc'
--- src/logic/map_objects/tribes/productionsite.cc	2016-03-02 08:28:09 +0000
+++ src/logic/map_objects/tribes/productionsite.cc	2016-03-10 14:42:34 +0000
@@ -114,7 +114,7 @@
 				}
 				DescriptionIndex const idx = egbase.tribes().ware_index(ware_name);
 				if (egbase.tribes().ware_exists(idx)) {
-					for (const WareAmount& temp_inputs : inputs()) {
+					for (const auto& temp_inputs : inputs()) {
 						if (temp_inputs.first == idx) {
 							throw wexception("duplicated");
 						}
@@ -143,7 +143,7 @@
 				}
 				DescriptionIndex const woi = egbase.tribes().worker_index(worker_name);
 				if (egbase.tribes().worker_exists(woi)) {
-					for (const WareAmount& wp : working_positions()) {
+					for (const auto& wp : working_positions()) {
 						if (wp.first == woi) {
 							throw wexception("duplicated");
 						}
@@ -426,7 +426,7 @@
 
 	//  Request missing workers.
 	WorkingPosition * wp = working_positions_;
-	for (const WareAmount& temp_wp : descr().working_positions()) {
+	for (const auto& temp_wp : descr().working_positions()) {
 		DescriptionIndex const worker_index = temp_wp.first;
 		for (uint32_t j =  temp_wp.second; j; --j, ++wp)
 			if (Worker * const worker = wp->worker)
@@ -543,7 +543,7 @@
 	molog("%s leaving\n", w.descr().descname().c_str());
 	WorkingPosition * wp = working_positions_;
 
-	for (const WareAmount& temp_wp : descr().working_positions()) {
+	for (const auto& temp_wp : descr().working_positions()) {
 		DescriptionIndex const worker_index = temp_wp.first;
 		for (uint32_t j = temp_wp.second; j; --j, ++wp) {
 			Worker * const worker = wp->worker;

=== modified file 'src/logic/map_objects/tribes/productionsite.h'
--- src/logic/map_objects/tribes/productionsite.h	2016-02-16 13:43:48 +0000
+++ src/logic/map_objects/tribes/productionsite.h	2016-03-10 14:42:34 +0000
@@ -67,7 +67,7 @@
 
 	uint32_t nr_working_positions() const {
 		uint32_t result = 0;
-		for (const WareAmount& working_pos : working_positions()) {
+		for (const auto& working_pos : working_positions()) {
 			result += working_pos.second;
 		}
 		return result;

=== modified file 'src/logic/map_objects/tribes/tribe_descr.cc'
--- src/logic/map_objects/tribes/tribe_descr.cc	2016-02-09 07:42:38 +0000
+++ src/logic/map_objects/tribes/tribe_descr.cc	2016-03-10 14:42:34 +0000
@@ -96,7 +96,7 @@
 					}
 					wares_.insert(wareindex);
 					column.push_back(wareindex);
-					wares_order_coords_[wareindex] = std::pair<uint32_t, uint32_t>(columnindex, rowindex);
+					wares_order_coords_[wareindex] = std::make_pair(columnindex, rowindex);
 				} catch (const WException& e) {
 					throw GameDataError("Failed adding ware '%s: %s", warenames[rowindex].c_str(), e.what());
 				}
@@ -121,7 +121,7 @@
 					}
 					workers_.insert(workerindex);
 					column.push_back(workerindex);
-					workers_order_coords_[workerindex] = std::pair<uint32_t, uint32_t>(columnindex, rowindex);
+					workers_order_coords_[workerindex] = std::make_pair(columnindex, rowindex);
 
 					const WorkerDescr& worker_descr = *tribes_.get_worker_descr(workerindex);
 					if (worker_descr.is_buildable() && worker_descr.buildcost().empty()) {
@@ -161,12 +161,12 @@
 				buildings_.push_back(index);
 
 				// Register construction materials
-				for (WareAmount build_cost : get_building_descr(index)->buildcost()) {
+				for (const auto& build_cost : get_building_descr(index)->buildcost()) {
 					if (!is_construction_material(build_cost.first)) {
 						construction_materials_.insert(build_cost.first);
 					}
 				}
-				for (WareAmount enhancement_cost : get_building_descr(index)->enhancement_cost()) {
+				for (const auto& enhancement_cost : get_building_descr(index)->enhancement_cost()) {
 					if (!is_construction_material(enhancement_cost.first)) {
 						construction_materials_.insert(enhancement_cost.first);
 					}

=== modified file 'src/logic/map_objects/tribes/tribes.cc'
--- src/logic/map_objects/tribes/tribes.cc	2016-02-27 08:43:39 +0000
+++ src/logic/map_objects/tribes/tribes.cc	2016-03-10 14:42:34 +0000
@@ -360,13 +360,13 @@
 
 		// Add consumers and producers to wares.
 		if (upcast(ProductionSiteDescr, de, &building_descr)) {
-			for (const WareAmount& ware_amount : de->inputs()) {
+			for (const auto& ware_amount : de->inputs()) {
 				wares_->get_mutable(ware_amount.first)->add_consumer(i);
 			}
 			for (const DescriptionIndex& wareindex : de->output_ware_types()) {
 				wares_->get_mutable(wareindex)->add_producer(i);
 			}
-			for (const WareAmount& job : de->working_positions()) {
+			for (const auto& job : de->working_positions()) {
 				workers_->get_mutable(job.first)->add_employer(i);
 			}
 		}

=== modified file 'src/logic/map_objects/tribes/warehouse.cc'
--- src/logic/map_objects/tribes/warehouse.cc	2016-02-21 18:57:49 +0000
+++ src/logic/map_objects/tribes/warehouse.cc	2016-03-10 14:42:34 +0000
@@ -770,7 +770,7 @@
 {
 	PlayerImmovable::Workers all_workers;
 
-	for (const std::pair<DescriptionIndex, WorkerList>& worker_pair : incorporated_workers_) {
+	for (const auto& worker_pair : incorporated_workers_) {
 		for (Worker * worker : worker_pair.second) {
 			all_workers.push_back(worker);
 		}
@@ -1060,7 +1060,7 @@
 	}
 
 	//  see if we have the resources
-	for (const std::pair<std::string, uint8_t>& buildcost : w_desc.buildcost()) {
+	for (const auto& buildcost : w_desc.buildcost()) {
 		const std::string & input_name = buildcost.first;
 		DescriptionIndex id_w = owner().tribe().ware_index(input_name);
 		if (owner().tribe().has_ware(id_w)) {
@@ -1090,7 +1090,7 @@
 
 	const WorkerDescr & w_desc = *owner().tribe().get_worker_descr(worker);
 
-	for (const std::pair<std::string, uint8_t>& buildcost : w_desc.buildcost()) {
+	for (const auto& buildcost : w_desc.buildcost()) {
 		const std::string & input = buildcost.first;
 		DescriptionIndex const id_ware = owner().tribe().ware_index(input);
 		if (owner().tribe().has_ware(id_ware)) {
@@ -1138,7 +1138,7 @@
 	const WorkerDescr & w_desc = *owner().tribe().get_worker_descr(index);
 	std::vector<uint32_t> available;
 
-	for (const std::pair<std::string, uint8_t>& buildcost : w_desc.buildcost()) {
+	for (const auto& buildcost : w_desc.buildcost()) {
 		const std::string & input_name = buildcost.first;
 		DescriptionIndex id_w = owner().tribe().ware_index(input_name);
 		if (owner().tribe().has_ware(id_w)) {
@@ -1193,7 +1193,7 @@
 		pw->amount = 0;
 
 		const WorkerDescr & w_desc = *owner().tribe().get_worker_descr(pw->index);
-		for (const std::pair<std::string, uint8_t>& buildcost : w_desc.buildcost()) {
+		for (const auto& buildcost : w_desc.buildcost()) {
 			const std::string & input_name = buildcost.first;
 
 			DescriptionIndex id_w = owner().tribe().ware_index(input_name);
@@ -1232,7 +1232,7 @@
 	}
 
 	uint32_t idx = 0;
-	for (const std::pair<std::string, uint8_t>& buildcost : w_desc.buildcost()) {
+	for (const auto& buildcost : w_desc.buildcost()) {
 
 		const std::string & input_name = buildcost.first;
 		uint32_t supply;

=== modified file 'src/logic/map_objects/world/critter.cc'
--- src/logic/map_objects/world/critter.cc	2016-02-08 13:28:43 +0000
+++ src/logic/map_objects/world/critter.cc	2016-03-10 14:42:34 +0000
@@ -123,7 +123,7 @@
 }
 
 CritterDescr::~CritterDescr() {
-	for (std::pair<std::string, CritterProgram *> program : programs_) {
+	for (auto program : programs_) {
 		delete program.second;
 	}
 }

=== modified file 'src/logic/player.cc'
--- src/logic/player.cc	2016-03-08 08:22:28 +0000
+++ src/logic/player.cc	2016-03-10 14:42:34 +0000
@@ -354,7 +354,7 @@
 	const Map &       map      = game.map         ();
 	uint32_t    const gametime = game.get_gametime();
 	Coords      const position = m   .position    ();
-	for (std::pair<MessageId, Message *>  tmp_message : messages()) {
+	for (auto tmp_message : messages()) {
 		if
 			(tmp_message.second->type() == m.type()      &&
 			 gametime < tmp_message.second->sent() + timeout &&

=== modified file 'src/map_io/map_buildingdata_packet.cc'
--- src/map_io/map_buildingdata_packet.cc	2016-03-02 17:13:06 +0000
+++ src/map_io/map_buildingdata_packet.cc	2016-03-10 14:42:34 +0000
@@ -633,7 +633,7 @@
 				//  Find a working position that matches this request.
 				ProductionSite::WorkingPosition * wp = &wp_begin;
 				bool found_working_position = false;
-				for (const WareAmount& working_position : working_positions) {
+				for (const auto& working_position : working_positions) {
 					uint32_t count = working_position.second;
 					assert(count);
 					if (worker_index == working_position.first) {
@@ -672,7 +672,7 @@
 				const WorkerDescr & worker_descr = worker->descr();
 				ProductionSite::WorkingPosition * wp = &wp_begin;
 				bool found_working_position = false;
-				for (const WareAmount& working_position : working_positions) {
+				for (const auto& working_position : working_positions) {
 					uint32_t count = working_position.second;
 					assert(count);
 
@@ -1084,14 +1084,14 @@
 
 	//  Incorporated workers, write sorted after file-serial.
 	uint32_t nworkers = 0;
-	for (const std::pair<DescriptionIndex, Warehouse::WorkerList>& cwt: warehouse.incorporated_workers_) {
+	for (const auto& cwt: warehouse.incorporated_workers_) {
 		nworkers += cwt.second.size();
 	}
 
 	fw.unsigned_16(nworkers);
 	using TWorkerMap = std::map<uint32_t, const Worker *>;
 	TWorkerMap workermap;
-	for (const std::pair<DescriptionIndex, Warehouse::WorkerList>& cwt : warehouse.incorporated_workers_) {
+	for (const auto& cwt : warehouse.incorporated_workers_) {
 		for (Worker * temp_worker : cwt.second) {
 			const Worker & w = *temp_worker;
 			assert(mos.is_object_known(w));
@@ -1101,7 +1101,7 @@
 		}
 	}
 
-	for (const std::pair<uint32_t, const Worker *>& temp_worker : workermap) {
+	for (const auto& temp_worker : workermap) {
 		const Worker & obj = *temp_worker.second;
 		assert(mos.is_object_known(obj));
 		fw.unsigned_32(mos.get_object_file_index(obj));
@@ -1237,7 +1237,7 @@
 		 std::numeric_limits<uint8_t>::max());
 	fw.unsigned_8(productionsite.skipped_programs_.size());
 
-	for (const std::pair<std::string, Time>& temp_program : productionsite.skipped_programs_) {
+	for (const auto& temp_program : productionsite.skipped_programs_) {
 		fw.string    (temp_program.first);
 		fw.unsigned_32(temp_program.second);
 	}

=== modified file 'src/map_io/map_object_saver.cc'
--- src/map_io/map_object_saver.cc	2015-11-28 22:29:26 +0000
+++ src/map_io/map_object_saver.cc	2016-03-10 14:42:34 +0000
@@ -152,7 +152,7 @@
  * Return the number of unsaved objects
  */
 void MapObjectSaver::detect_unsaved_objects() const {
-	for (const std::pair<const MapObject *, MapObjectRec>& temp_map : m_objects) {
+	for (const auto& temp_map : m_objects) {
 		if (!temp_map.second.saved) {
 			throw wexception
 				("%s has not been saved", temp_map.second.description.c_str());

=== modified file 'src/map_io/map_players_messages_packet.cc'
--- src/map_io/map_players_messages_packet.cc	2016-01-28 05:24:34 +0000
+++ src/map_io/map_players_messages_packet.cc	2016-03-10 14:42:34 +0000
@@ -173,7 +173,7 @@
 			("packet_version", kCurrentPacketVersion);
 		const MessageQueue & messages = player->messages();
 		MapMessageSaver & message_saver = mos.message_savers[p - 1];
-		for (const std::pair<MessageId, Message *>& temp_message : messages) {
+		for (const auto& temp_message : messages) {
 			message_saver.add         (temp_message.first);
 			const Message & message = *temp_message.second;
 			assert(message.sent() <= static_cast<uint32_t>(egbase.get_gametime()));

=== modified file 'src/scripting/lua_game.cc'
--- src/scripting/lua_game.cc	2016-02-13 08:47:22 +0000
+++ src/scripting/lua_game.cc	2016-03-10 14:42:34 +0000
@@ -202,7 +202,7 @@
 
 	lua_newtable(L);
 	uint32_t cidx = 1;
-	for (const std::pair<MessageId, Message *>& temp_message : p.messages()) {
+	for (const auto& temp_message : p.messages()) {
 		if (temp_message.second->status() == Message::Status::kArchived)
 			continue;
 

=== modified file 'src/scripting/lua_map.cc'
--- src/scripting/lua_map.cc	2016-03-02 17:13:06 +0000
+++ src/scripting/lua_map.cc	2016-03-10 14:42:34 +0000
@@ -264,7 +264,7 @@
 WorkersMap get_valid_workers_for(const ProductionSite& ps)
 {
 	WorkersMap rv;
-	for (const Widelands::WareAmount& item : ps.descr().working_positions()) {
+	for (const auto& item : ps.descr().working_positions()) {
 		rv.insert(WorkerAmount(item.first, item.second));
 	}
 	return rv;
@@ -1957,7 +1957,7 @@
 int LuaProductionSiteDescription::get_inputs(lua_State * L) {
 	lua_newtable(L);
 	int index = 1;
-	for (const WareAmount& input_ware : get()->inputs()) {
+	for (const auto& input_ware : get()->inputs()) {
 		lua_pushint32(L, index++);
 		const WareDescr* descr = get_egbase(L).tribes().get_ware_descr(input_ware.first);
 		to_lua<LuaWareDescription>(L, new LuaWareDescription(descr));
@@ -2058,7 +2058,7 @@
 		const ProductionProgram& program = *programs.at(program_name);
 		lua_newtable(L);
 		int counter = 0;
-		for (const Widelands::ProductionProgram::WareTypeGroup& group: program.consumed_wares()) {
+		for (const auto& group: program.consumed_wares()) {
 			lua_pushnumber(L, ++counter);
 			lua_newtable(L);
 			for (const DescriptionIndex& ware_index : group.first) {
@@ -2656,7 +2656,7 @@
 	lua_newtable(L);
 	int index = 1;
 	if (get()->is_buildable()) {
-		for (const std::pair<std::string, uint8_t>& buildcost_pair : get()->buildcost()) {
+		for (const auto& buildcost_pair : get()->buildcost()) {
 			lua_pushint32(L, index++);
 			lua_pushstring(L, buildcost_pair.first);
 			lua_settable(L, -3);
@@ -3451,7 +3451,7 @@
 
 	uint32_t nwares = 0;
 
-	for (const std::pair<Widelands::DescriptionIndex, uint32_t>& ware : c_wares) {
+	for (const auto& ware : c_wares) {
 		// all wares currently on the flag without a setpoint should be removed
 		if (!setpoints.count(ware.first))
 			setpoints.insert(Widelands::WareAmount(ware.first, 0));
@@ -3459,7 +3459,7 @@
 	}
 
 	// The idea is to change as little as possible on this flag
-	for (const std::pair<Widelands::DescriptionIndex, uint32_t>& sp : setpoints) {
+	for (const auto& sp : setpoints) {
 		uint32_t cur = 0;
 		WaresMap::iterator i = c_wares.find(sp.first);
 		if (i != c_wares.end())
@@ -3509,7 +3509,7 @@
 	if (wares_set.size() == flag->owner().tribe().get_nrwares()) { // Want all returned
 		wares_set.clear();
 
-		for (const std::pair<Widelands::DescriptionIndex, uint32_t>& ware : wares) {
+		for (const auto& ware : wares) {
 			wares_set.insert(ware.first);
 		}
 	}
@@ -4054,7 +4054,7 @@
 	ProductionSite * ps = get(L, egbase);
 
 	lua_newtable(L);
-	for (const WareAmount& input_ware : ps->descr().inputs()) {
+	for (const auto& input_ware : ps->descr().inputs()) {
 		const WareDescr* descr = egbase.tribes().get_ware_descr(input_ware.first);
 		lua_pushstring(L, descr->name());
 		lua_pushuint32(L, input_ware.second);
@@ -4082,10 +4082,10 @@
 	WaresMap setpoints = m_parse_set_wares_arguments(L, tribe);
 
 	WaresSet valid_wares;
-	for (const WareAmount& input_ware : ps->descr().inputs()) {
+	for (const auto& input_ware : ps->descr().inputs()) {
 		valid_wares.insert(input_ware.first);
 	}
-	for (const std::pair<Widelands::DescriptionIndex, uint32_t>& sp : setpoints) {
+	for (const auto& sp : setpoints) {
 		if (!valid_wares.count(sp.first)) {
 			report_error(
 				L, "<%s> can't be stored in this building: %s!",
@@ -4112,7 +4112,7 @@
 	WaresSet wares_set = m_parse_get_wares_arguments(L, tribe, &return_number);
 
 	WaresSet valid_wares;
-	for (const WareAmount& input_ware : ps->descr().inputs()) {
+	for (const auto& input_ware : ps->descr().inputs()) {
 		valid_wares.insert(input_ware.first);
 	}
 

=== modified file 'src/sound/sound_handler.cc'
--- src/sound/sound_handler.cc	2016-01-28 05:24:34 +0000
+++ src/sound/sound_handler.cc	2016-03-10 14:42:34 +0000
@@ -391,7 +391,7 @@
 
 	// starting a block, so I can define a local type for iterating
 	{
-		for (const std::pair<uint32_t, std::string> fx_pair : active_fx_) {
+		for (const auto& fx_pair : active_fx_) {
 			if (fx_pair.second == fx_name) {
 				already_running = true;
 				break;

=== modified file 'src/wui/game_message_menu.cc'
--- src/wui/game_message_menu.cc	2016-02-01 17:17:45 +0000
+++ src/wui/game_message_menu.cc	2016-03-10 14:42:34 +0000
@@ -311,7 +311,7 @@
 	}
 
 	// Add new messages to the list
-	for (const std::pair<MessageId, Message *>& temp_message : mq) {
+	for (const auto& temp_message : mq) {
 		MessageId      const id      =  temp_message.first;
 		const Message &       message = *temp_message.second;
 		Message::Status const status  = message.status();

=== modified file 'src/wui/waresdisplay.cc'
--- src/wui/waresdisplay.cc	2016-02-08 20:53:35 +0000
+++ src/wui/waresdisplay.cc	2016-03-10 14:42:34 +0000
@@ -162,7 +162,7 @@
 
 	// Release anchor, empty selection
 	selection_anchor_ = Widelands::INVALID_INDEX;
-	for (std::pair<const Widelands::DescriptionIndex&, bool> resetme : in_selection_) {
+	for (auto& resetme : in_selection_) {
 		in_selection_[resetme.first] = false;
 	}
 	return true;
@@ -207,7 +207,7 @@
 		return;
 	}
 
-	for (std::pair<const Widelands::DescriptionIndex&, bool> resetme : in_selection_) {
+	for (auto& resetme : in_selection_) {
 		in_selection_[resetme.first] = false;
 	}
 


Follow ups