Skip to content

Commit

Permalink
BOOST_FOREACH -> range for
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Apr 2, 2016
1 parent 104ccf6 commit ca38201
Show file tree
Hide file tree
Showing 206 changed files with 1,263 additions and 1,520 deletions.
21 changes: 10 additions & 11 deletions src/about.cpp
Expand Up @@ -38,7 +38,6 @@
#include "widgets/button.hpp" // for button

#include <algorithm> // for max
#include <boost/foreach.hpp> // for auto_any_base, etc
#include <boost/scoped_ptr.hpp> // for scoped_ptr
#include <map> // for map, map<>::mapped_type
#include <ostream> // for operator<<, basic_ostream, etc
Expand Down Expand Up @@ -71,7 +70,7 @@ static void add_lines(std::vector<std::string> &res, config const &c, bool split
// get slight scrolling glitches in the credits screen.
const std::vector<std::string>& lines = utils::split(c["title"], '\n');
bool first = true;
BOOST_FOREACH(const std::string& line, lines) {
for(const std::string& line : lines) {
if(first) {
res.push_back("+" + line);
first = false;
Expand All @@ -87,7 +86,7 @@ static void add_lines(std::vector<std::string> &res, config const &c, bool split
}

std::vector<std::string> lines = utils::split(c["text"], '\n');
BOOST_FOREACH(std::string &line, lines)
for(std::string &line : lines)
{
if (line.size() > 1 && line[0] == '+')
line = "+ " + line.substr(1);
Expand All @@ -102,7 +101,7 @@ static void add_lines(std::vector<std::string> &res, config const &c, bool split
}
}

BOOST_FOREACH(const config &entry, c.child_range("entry")) {
for (const config &entry : c.child_range("entry")) {
res.push_back("- "+ entry["name"].str());
}
}
Expand All @@ -115,15 +114,15 @@ std::vector<std::string> get_text(const std::string &campaign, bool split_multil
config::child_itors about_entries = about_list.child_range("about");

if (!campaign.empty()) {
BOOST_FOREACH(const config &about, about_entries) {
for (const config &about : about_entries) {
// just finished a particular campaign
if (campaign == about["id"]) {
add_lines(res, about, split_multiline_headers);
}
}
}

BOOST_FOREACH(const config &about, about_entries) {
for (const config &about : about_entries) {
add_lines(res, about, split_multiline_headers);
}

Expand All @@ -136,7 +135,7 @@ void set_about(const config &cfg)
images.clear();
images_default = "";

BOOST_FOREACH(const config &about, cfg.child_range("about"))
for (const config &about : cfg.child_range("about"))
{
about_list.add_child("about", about);
const std::string &im = about["images"];
Expand All @@ -149,7 +148,7 @@ void set_about(const config &cfg)
}
}

BOOST_FOREACH(const config &campaign, cfg.child_range("campaign"))
for (const config &campaign : cfg.child_range("campaign"))
{
config::const_child_itors abouts = campaign.child_range("about");
if (abouts.first == abouts.second) continue;
Expand All @@ -161,7 +160,7 @@ void set_about(const config &cfg)
temp["id"] = id;
std::string campaign_images;

BOOST_FOREACH(const config &about, abouts)
for (const config &about : abouts)
{
const std::string &subtitle = about["title"];
if (!subtitle.empty())
Expand All @@ -174,12 +173,12 @@ void set_about(const config &cfg)
text << '\n';
}

BOOST_FOREACH(const std::string &line, utils::split(about["text"], '\n'))
for (const std::string &line : utils::split(about["text"], '\n'))
{
text << " " << line << '\n';
}

BOOST_FOREACH(const config &entry, about.child_range("entry"))
for (const config &entry : about.child_range("entry"))
{
text << " " << entry["name"] << '\n';
}
Expand Down
2 changes: 0 additions & 2 deletions src/actions/attack.cpp
Expand Up @@ -53,8 +53,6 @@
#include "whiteboard/manager.hpp"
#include "wml_exception.hpp"

#include <boost/foreach.hpp>

static lg::log_domain log_engine("engine");
#define DBG_NG LOG_STREAM(debug, log_engine)
#define LOG_NG LOG_STREAM(info, log_engine)
Expand Down
5 changes: 2 additions & 3 deletions src/actions/create.cpp
Expand Up @@ -51,7 +51,6 @@
#include "variable.hpp"
#include "whiteboard/manager.hpp"

#include <boost/foreach.hpp>
#include <boost/scoped_ptr.hpp>

static lg::log_domain log_engine("engine");
Expand Down Expand Up @@ -140,7 +139,7 @@ namespace { // Helpers for get_recalls()

const unit_filter ufilt(vconfig(leader->recall_filter()), resources::filter_con);

BOOST_FOREACH(const unit_const_ptr & recall_unit_ptr, leader_team.recall_list())
for (const unit_const_ptr & recall_unit_ptr : leader_team.recall_list())
{
const unit & recall_unit = *recall_unit_ptr;
// Do not add a unit twice.
Expand Down Expand Up @@ -220,7 +219,7 @@ std::vector<unit_const_ptr > get_recalls(int side, const map_location &recall_lo
if ( !leader_in_place )
{
// Return the full recall list.
BOOST_FOREACH(const unit_const_ptr & recall, (*resources::teams)[side-1].recall_list())
for (const unit_const_ptr & recall : (*resources::teams)[side-1].recall_list())
{
result.push_back(recall);
}
Expand Down
10 changes: 4 additions & 6 deletions src/actions/heal.cpp
Expand Up @@ -32,7 +32,6 @@
#include "units/udisplay.hpp"
#include "units/map.hpp"

#include <boost/foreach.hpp>
#include <list>
#include <vector>

Expand Down Expand Up @@ -98,8 +97,7 @@ namespace {
return POISON_CURE;

// Regeneration?
BOOST_FOREACH (const unit_ability & regen,
patient.get_abilities("regenerate"))
for (const unit_ability & regen : patient.get_abilities("regenerate"))
{
curing = std::max(curing, poison_status((*regen.first)["poison"]));
if ( curing == POISON_CURE )
Expand All @@ -111,7 +109,7 @@ namespace {
// Look through the healers to find a curer.
unit_map::iterator curer = units.end();
// Assumed: curing is not POISON_CURE at the start of any iteration.
BOOST_FOREACH (const unit_ability & heal, patient.get_abilities("heals"))
for (const unit_ability & heal : patient.get_abilities("heals"))
{
POISON_STATUS this_cure = poison_status((*heal.first)["poison"]);
if ( this_cure <= curing )
Expand Down Expand Up @@ -219,7 +217,7 @@ namespace {
if ( update_healing(healing, harming, heal_effect.get_composite_value()) )
{
// Collect the healers involved.
BOOST_FOREACH (const unit_abilities::individual_effect & heal, heal_effect)
for (const unit_abilities::individual_effect & heal : heal_effect)
healers.push_back(&*units.find(heal.loc));

if ( !healers.empty() ) {
Expand Down Expand Up @@ -300,7 +298,7 @@ void calculate_healing(int side, bool update_display)
std::list<heal_unit> unit_list;

// We look for all allied units, then we see if our healer is near them.
BOOST_FOREACH(unit &patient, *resources::units) {
for (unit &patient : *resources::units) {

if ( patient.get_state("unhealable") || patient.incapacitated() ) {
if ( patient.side() == side )
Expand Down
5 changes: 2 additions & 3 deletions src/actions/move.cpp
Expand Up @@ -46,7 +46,6 @@
#include "units/animation_component.hpp"
#include "whiteboard/manager.hpp"

#include <boost/foreach.hpp>
#include <deque>
#include <map>
#include <set>
Expand Down Expand Up @@ -585,7 +584,7 @@ namespace { // Private helpers for move_unit()
reveal_ambusher(blocked_loc_, false);

// Reveal ambushers.
BOOST_FOREACH(const map_location & reveal, ambushers_) {
for(const map_location & reveal : ambushers_) {
reveal_ambusher(reveal, true);
}

Expand Down Expand Up @@ -840,7 +839,7 @@ namespace { // Private helpers for move_unit()
*/
std::string unit_mover::read_ambush_string(const unit & ambusher)
{
BOOST_FOREACH( const unit_ability &hide, ambusher.get_abilities("hides") )
for(const unit_ability &hide : ambusher.get_abilities("hides"))
{
const std::string & ambush_string = (*hide.first)["alert"].str();
if ( !ambush_string.empty() )
Expand Down
5 changes: 2 additions & 3 deletions src/actions/undo.cpp
Expand Up @@ -54,7 +54,6 @@
#include "undo_update_shroud_action.hpp"

#include <algorithm> // for reverse
#include <boost/foreach.hpp> // for auto_any_base, etc
#include <boost/intrusive_ptr.hpp> // for intrusive_ptr
#include <boost/ptr_container/detail/static_move_ptr.hpp>
#include <boost/ptr_container/detail/void_ptr_iterator.hpp>
Expand Down Expand Up @@ -299,7 +298,7 @@ void undo_list::read(const config & cfg)
committed_actions_ = committed_actions_ || cfg["committed"].to_bool();

// Build the undo stack.
BOOST_FOREACH( const config & child, cfg.child_range("undo") ) {
for (const config & child : cfg.child_range("undo")) {
try {
undo_action_base * action = create_action(child);
if ( action ) {
Expand All @@ -317,7 +316,7 @@ void undo_list::read(const config & cfg)
}

// Build the redo stack.
BOOST_FOREACH( const config & child, cfg.child_range("redo") ) {
for (const config & child : cfg.child_range("redo")) {
try {
undo_action_base * action = create_action(child);
if ( undo_action* undoable_action = dynamic_cast<undo_action*>(action)) {
Expand Down
7 changes: 3 additions & 4 deletions src/actions/undo_action.cpp
Expand Up @@ -5,14 +5,13 @@
#include "game_events/pump.hpp" //game_events::queued_event

#include <cassert>
#include <boost/foreach.hpp>

namespace actions
{
void undo_action::execute_undo_umc_wml()
{
assert(resources::lua_kernel);
BOOST_FOREACH(const config& c, umc_commands_undo)
for(const config& c : umc_commands_undo)
{
resources::lua_kernel->run_wml_action("command", vconfig(c), game_events::queued_event("undo", map_location(), map_location(), config()));
}
Expand All @@ -21,7 +20,7 @@ void undo_action::execute_undo_umc_wml()
void undo_action::execute_redo_umc_wml()
{
assert(resources::lua_kernel);
BOOST_FOREACH(const config& c, umc_commands_redo)
for(const config& c : umc_commands_redo)
{
resources::lua_kernel->run_wml_action("command", vconfig(c), game_events::queued_event("redo", map_location(), map_location(), config()));
}
Expand All @@ -34,7 +33,7 @@ void undo_action::read_tconfig_vector(tconfig_vector& vec, const config& cfg, co
}
void undo_action::write_tconfig_vector(const tconfig_vector& vec, config& cfg, const std::string& tag)
{
BOOST_FOREACH(const config& c, vec)
for(const config& c : vec)
{
cfg.add_child(tag, c);
}
Expand Down
3 changes: 1 addition & 2 deletions src/actions/unit_creator.cpp
Expand Up @@ -40,7 +40,6 @@

#include "game_display.hpp" // for resources::screen

#include <boost/foreach.hpp>
#include <boost/scoped_ptr.hpp>

static lg::log_domain log_engine("engine");
Expand Down Expand Up @@ -113,7 +112,7 @@ map_location unit_creator::find_location(const config &cfg, const unit* pass_che
placements.push_back("map");
placements.push_back("recall");

BOOST_FOREACH(const std::string& place, placements)
for (const std::string& place : placements)
{
map_location loc;

Expand Down
22 changes: 10 additions & 12 deletions src/actions/vision.cpp
Expand Up @@ -35,8 +35,6 @@
#include "team.hpp"
#include "units/unit.hpp"

#include <boost/foreach.hpp>

class unit_animation;

static lg::log_domain log_engine("engine");
Expand All @@ -57,13 +55,13 @@ static void create_jamming_map(std::map<map_location, int> & jamming,
jamming.clear();

// Build the map.
BOOST_FOREACH (const unit &u, *resources::units)
for (const unit &u : *resources::units)
{
if ( u.jamming() < 1 || !view_team.is_enemy(u.side()) )
continue;

pathfind::jamming_path jam_path(u, u.get_location());
BOOST_FOREACH(const pathfind::paths::step& st, jam_path.destinations) {
for (const pathfind::paths::step& st : jam_path.destinations) {
if ( jamming[st.curr] < st.move_left )
jamming[st.curr] = st.move_left;
}
Expand Down Expand Up @@ -365,14 +363,14 @@ bool shroud_clearer::clear_unit(const map_location &view_loc, team &view_team,
resources::screen->draw(true);

// Clear the fog.
BOOST_FOREACH (const pathfind::paths::step &dest, sight.destinations) {
for (const pathfind::paths::step &dest : sight.destinations) {
bool known = known_units && known_units->count(dest.curr) != 0;
if ( clear_loc(view_team, dest.curr, view_loc, real_loc, viewer_id, !known,
*enemy_count, *friend_count, spectator) )
cleared_something = true;
}
//TODO guard with game_config option
BOOST_FOREACH (const map_location &dest, sight.edges) {
for (const map_location &dest : sight.edges) {
bool known = known_units && known_units->count(dest) != 0;
if ( clear_loc(view_team, dest, view_loc, real_loc, viewer_id, !known,
*enemy_count, *friend_count, spectator) )
Expand Down Expand Up @@ -558,7 +556,7 @@ bool shroud_clearer::fire_events()
std::vector<sight_data> sight_list;
sight_list.swap(sightings_);

BOOST_FOREACH (const sight_data & event, sight_list) {
for (const sight_data & event : sight_list) {
// Try to locate the sighting unit.
unit_map::const_iterator find_it = units.find(event.sighter_id);
const map_location & sight_loc =
Expand Down Expand Up @@ -641,7 +639,7 @@ bool actor_sighted(const unit & target, const std::vector<int> * cache)
std::vector<bool> needs_event(teams_size, cache == nullptr);
if ( cache != nullptr ) {
// Flag just the sides in the cache as needing events.
BOOST_FOREACH (int side, *cache)
for (int side : *cache)
needs_event[side-1] = true;
}
// Exclude the target's own team.
Expand All @@ -659,7 +657,7 @@ bool actor_sighted(const unit & target, const std::vector<int> * cache)
// Look for units that can be used as the second unit in sighted events.
std::vector<const unit *> second_units(teams_size, nullptr);
std::vector<size_t> distances(teams_size, UINT_MAX);
BOOST_FOREACH (const unit & viewer, *resources::units) {
for (const unit & viewer : *resources::units) {
const size_t index = viewer.side() - 1;
// Does viewer belong to a team for which we still need a unit?
if ( needs_event[index] && distances[index] != 0 ) {
Expand Down Expand Up @@ -713,7 +711,7 @@ void recalculate_fog(int side)

// Exclude currently seen units from sighted events.
std::set<map_location> visible_locs;
BOOST_FOREACH (const unit &u, *resources::units) {
for (const unit &u : *resources::units) {
const map_location & u_location = u.get_location();

if ( !tm.fogged(u_location) )
Expand All @@ -726,7 +724,7 @@ void recalculate_fog(int side)
resources::screen->invalidate_all();

shroud_clearer clearer;
BOOST_FOREACH(const unit &u, *resources::units)
for (const unit &u : *resources::units)
{
if ( u.side() == side )
clearer.clear_unit(u.get_location(), u, tm, &visible_locs);
Expand Down Expand Up @@ -762,7 +760,7 @@ bool clear_shroud(int side, bool reset_fog, bool fire_events)
bool result = false;

shroud_clearer clearer;
BOOST_FOREACH(const unit &u, *resources::units)
for (const unit &u : *resources::units)
{
if ( u.side() == side )
result |= clearer.clear_unit(u.get_location(), u, tm);
Expand Down

0 comments on commit ca38201

Please sign in to comment.