Skip to content

Commit

Permalink
Remove custom FOREACH macro in favour of range-for
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Apr 1, 2016
1 parent f497d4c commit 982394f
Show file tree
Hide file tree
Showing 80 changed files with 303 additions and 395 deletions.
2 changes: 1 addition & 1 deletion projectfiles/CodeBlocks/wesnoth.cbp
Expand Up @@ -1064,7 +1064,7 @@
<Unit filename="../../src/util.hpp" />
<Unit filename="../../src/utils/boost_function_guarded.hpp" />
<Unit filename="../../src/utils/const_clone.hpp" />
<Unit filename="../../src/utils/foreach.hpp" />
<Unit filename="../../src/utils/iterable_pair.hpp" />
<Unit filename="../../src/utils/iterator.hpp" />
<Unit filename="../../src/utils/make_enum.cpp" />
<Unit filename="../../src/utils/make_enum.hpp" />
Expand Down
2 changes: 1 addition & 1 deletion projectfiles/VC9/wesnoth.vcproj
Expand Up @@ -14865,7 +14865,7 @@
>
</File>
<File
RelativePath="..\..\src\utils\foreach.hpp"
RelativePath="..\..\src\utils\iterable_pair.hpp"
>
</File>
<File
Expand Down
4 changes: 2 additions & 2 deletions projectfiles/Xcode/Wesnoth.xcodeproj/project.pbxproj
Expand Up @@ -1516,6 +1516,7 @@
911F2DAE1BA086F900E3102E /* alpha.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = alpha.cpp; sourceTree = "<group>"; };
911F2DAF1BA086FA00E3102E /* alpha.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = alpha.hpp; sourceTree = "<group>"; };
911F2DB11BA0870E00E3102E /* compat.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = compat.hpp; sourceTree = "<group>"; };
911F471B1CAE5A7E00F47035 /* iterable_pair.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = iterable_pair.hpp; sourceTree = "<group>"; };
9122417A1CAAB7B7008B347F /* loadscreen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = loadscreen.cpp; sourceTree = "<group>"; };
9122417B1CAAB7B7008B347F /* loadscreen.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = loadscreen.hpp; sourceTree = "<group>"; };
91273E721C7BF1C0005E7F81 /* _main.cfg */ = {isa = PBXFileReference; lastKnownFileType = text; path = _main.cfg; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1699,7 +1700,6 @@
91ECD5D11BA11A5200B25CF1 /* unit_creator.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = unit_creator.hpp; sourceTree = "<group>"; };
91EF6BFB1C9E22E400E2A733 /* boost_function_guarded.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = boost_function_guarded.hpp; sourceTree = "<group>"; };
91EF6BFC1C9E22E400E2A733 /* const_clone.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = const_clone.hpp; sourceTree = "<group>"; };
91EF6BFE1C9E22E400E2A733 /* foreach.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = foreach.hpp; sourceTree = "<group>"; };
91EF6BFF1C9E22E400E2A733 /* iterator.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = iterator.hpp; sourceTree = "<group>"; };
91EF6C001C9E22E400E2A733 /* reference_counter.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = reference_counter.hpp; sourceTree = "<group>"; };
91EF6C011C9E22E400E2A733 /* sha1.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = sha1.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3565,7 +3565,7 @@
children = (
91EF6BFB1C9E22E400E2A733 /* boost_function_guarded.hpp */,
91EF6BFC1C9E22E400E2A733 /* const_clone.hpp */,
91EF6BFE1C9E22E400E2A733 /* foreach.hpp */,
911F471B1CAE5A7E00F47035 /* iterable_pair.hpp */,
91EF6BFF1C9E22E400E2A733 /* iterator.hpp */,
EC53B04D1B23BB0E002F758F /* make_enum.cpp */,
91B621931B76720B00B00E0F /* make_enum.hpp */,
Expand Down
1 change: 1 addition & 0 deletions src/config.hpp
Expand Up @@ -49,6 +49,7 @@

#include "exceptions.hpp"
#include "tstring.hpp"
#include "utils/iterable_pair.hpp"

#ifdef HAVE_CXX14
# ifdef __clang__ // Check this first, because clang also defines __GNUC__
Expand Down
5 changes: 2 additions & 3 deletions src/formula/callable_objects.cpp
Expand Up @@ -15,7 +15,6 @@
#include "formula/callable_objects.hpp"
#include "units/unit.hpp"
#include "units/formula_manager.hpp"
#include "utils/foreach.hpp"

template <typename T, typename K>
variant convert_map( const std::map<T, K>& input_map ) {
Expand Down Expand Up @@ -109,7 +108,7 @@ variant attack_type_callable::get_value(const std::string& key) const
const config specials = att_.specials();
std::vector<variant> res;

FOREACH(const AUTO& special , specials.all_children_range()) {
for(const auto& special : specials.all_children_range()) {
if(!special.cfg["id"].empty()) {
res.push_back(variant(special.cfg["id"].str()));
}
Expand Down Expand Up @@ -393,7 +392,7 @@ variant unit_type_callable::get_value(const std::string& key) const
} else if(key == "traits") {
std::vector<variant> res;

FOREACH(const AUTO& config , u_.possible_traits())
for(const auto& config : u_.possible_traits())
{
res.push_back(variant(config["id"].str()));
}
Expand Down
6 changes: 2 additions & 4 deletions src/game_board.cpp
Expand Up @@ -21,8 +21,6 @@
#include "terrain/type_data.hpp"
#include "units/unit.hpp"

#include "utils/foreach.hpp"

#include <boost/foreach.hpp>
#include <set>
#include <vector>
Expand Down Expand Up @@ -263,7 +261,7 @@ boost::optional<std::string> game_board::replace_map(const gamemap & newmap) {

/* Remember the locations where a village is owned by a side. */
std::map<map_location, int> villages;
FOREACH(const AUTO& village, map_->villages()) {
for(const auto& village : map_->villages()) {
const int owner = village_owner(village);
if(owner != -1) {
villages[village] = owner;
Expand All @@ -282,7 +280,7 @@ boost::optional<std::string> game_board::replace_map(const gamemap & newmap) {
}

/* Disown villages that are no longer villages. */
FOREACH(const AUTO& village, villages) {
for(const auto& village : villages) {
if(!newmap.is_village(village.first)) {
teams_[village.second].lose_village(village.first);
}
Expand Down
54 changes: 27 additions & 27 deletions src/game_initialization/depcheck.cpp
Expand Up @@ -69,7 +69,7 @@ manager::manager(const config& gamecfg, bool mp, CVideo& video)
, prev_mods_()
{
DBG_MP << "Initializing the dependency manager" << std::endl;
BOOST_FOREACH (const config& cfg, gamecfg.child_range("modification")) {
for (const config& cfg : gamecfg.child_range("modification")) {
component_availabilty type = cfg["type"].to_enum<component_availabilty>(component_availabilty::HYBRID);
if((type != component_availabilty::MP || mp) && (type != component_availabilty::SP || !mp) ) {
config info;
Expand All @@ -84,7 +84,7 @@ manager::manager(const config& gamecfg, bool mp, CVideo& video)
}
}

BOOST_FOREACH (const config& cfg, gamecfg.child_range("era")) {
for (const config& cfg : gamecfg.child_range("era")) {
component_availabilty type = cfg["type"].to_enum<component_availabilty>(component_availabilty::MP);
if((type != component_availabilty::MP || mp) && (type != component_availabilty::SP || !mp) ) {
config info;
Expand All @@ -98,7 +98,7 @@ manager::manager(const config& gamecfg, bool mp, CVideo& video)
}
}

BOOST_FOREACH (const config& cfg, gamecfg.child_range("multiplayer")) {
for (const config& cfg : gamecfg.child_range("multiplayer")) {
if (cfg["allow_new_game"].to_bool(true)) {
config info;
info["id"] = cfg["id"];
Expand Down Expand Up @@ -131,7 +131,7 @@ void manager::revert()

bool manager::exists(const elem& e) const
{
BOOST_FOREACH (const config& cfg, depinfo_.child_range(e.type)) {
for (const config& cfg : depinfo_.child_range(e.type)) {
if (cfg["id"] == e.id) {
return true;
}
Expand All @@ -154,7 +154,7 @@ std::vector<std::string>

std::vector<std::string> items = get_required(e);

BOOST_FOREACH (const std::string& str, items) {
for (const std::string& str : items) {
if (!exists(elem(str, "modification"))) {
result.push_back(str);
}
Expand Down Expand Up @@ -185,7 +185,7 @@ std::vector<std::string> manager::get_required_not_enabled(const elem& e) const
std::vector<std::string> required = get_required(e);
std::vector<std::string> result;

BOOST_FOREACH (std::string str, required) {
for (std::string str : required) {
if ( !util::contains(mods_, str) ) {
result.push_back(str);
}
Expand All @@ -198,7 +198,7 @@ std::vector<std::string> manager::get_conflicting_enabled(const elem& e) const
{
std::vector<std::string> result;

BOOST_FOREACH(const std::string& mod, mods_) {
for (const std::string& mod : mods_) {
if (conflicts(elem(mod, "modification"), e)) {
result.push_back(mod);
}
Expand Down Expand Up @@ -277,26 +277,26 @@ bool manager::conflicts(const elem& elem1, const elem& elem2, bool directonly) c
std::vector<std::string> req1 = get_required(elem1),
req2 = get_required(elem2);

BOOST_FOREACH (const std::string& s, req1) {
for (const std::string& s : req1) {
elem m(s, "modification");

if (conflicts(elem2, m, true)) {
return true;
}
}

BOOST_FOREACH (const std::string& s, req2) {
for (const std::string& s : req2) {
elem m(s, "modification");

if (conflicts(elem1, m, true)) {
return true;
}
}

BOOST_FOREACH (const std::string& id1, req1) {
for (const std::string& id1 : req1) {
elem m1(id1, "modification");

BOOST_FOREACH (const std::string& id2, req2) {
for (const std::string& id2 : req2) {
elem m2(id2, "modification");

if (conflicts(m1, m2)) {
Expand Down Expand Up @@ -392,7 +392,7 @@ void manager::try_scenario_by_index(int index, bool force)
int manager::get_era_index() const
{
int result = 0;
BOOST_FOREACH (const config& i, depinfo_.child_range("era"))
for (const config& i : depinfo_.child_range("era"))
{
if (i["id"] == era_) {
return result;
Expand All @@ -407,7 +407,7 @@ int manager::get_scenario_index() const
{
int result = 0;

BOOST_FOREACH (const config& i, depinfo_.child_range("scenario"))
for (const config& i : depinfo_.child_range("scenario"))
{
if (i["id"] == scenario_) {
return result;
Expand All @@ -430,7 +430,7 @@ bool manager::enable_mods_dialog(const std::vector<std::string>& mods,
const std::string& requester)
{
std::vector<std::string> items;
BOOST_FOREACH (const std::string& mod, mods) {
for (const std::string& mod : mods) {
items.push_back(depinfo_.find_child("modification", "id", mod)["name"]);
}

Expand All @@ -442,7 +442,7 @@ bool manager::disable_mods_dialog(const std::vector<std::string>& mods,
const std::string& requester)
{
std::vector<std::string> items;
BOOST_FOREACH (const std::string& mod, mods) {
for (const std::string& mod : mods) {
items.push_back(depinfo_.find_child("modification", "id", mod)["name"]);
}

Expand All @@ -453,7 +453,7 @@ bool manager::disable_mods_dialog(const std::vector<std::string>& mods,
std::string manager::change_era_dialog(const std::vector<std::string>& eras)
{
std::vector<std::string> items;
BOOST_FOREACH(const std::string& era, eras) {
for(const std::string& era : eras) {
items.push_back(depinfo_.find_child("era", "id", era)["name"]);
}

Expand All @@ -470,7 +470,7 @@ std::string
manager::change_scenario_dialog(const std::vector<std::string>& scenarios)
{
std::vector<std::string> items;
BOOST_FOREACH (const std::string& scenario, scenarios) {
for (const std::string& scenario : scenarios) {
items.push_back(depinfo_.find_child("scenario", "id", scenario)["name"]);
}

Expand Down Expand Up @@ -542,7 +542,7 @@ bool manager::change_scenario(const std::string& id)
}

std::vector<std::string> newmods = req;
BOOST_FOREACH (const std::string& i, mods_) {
for (const std::string& i : mods_) {
if ( !util::contains(con, i) ) {
newmods.push_back(i);
}
Expand All @@ -558,7 +558,7 @@ bool manager::change_scenario(const std::string& id)
}

std::vector<std::string> compatible;
BOOST_FOREACH (const config& i, depinfo_.child_range("era")) {
for (const config& i : depinfo_.child_range("era")) {
if (!conflicts(scen, elem(i["id"], "era"))) {
compatible.push_back(i["id"]);
}
Expand Down Expand Up @@ -612,7 +612,7 @@ bool manager::change_era(const std::string& id)
}

std::vector<std::string> newmods = req;
BOOST_FOREACH (const std::string& i, mods_) {
for (const std::string& i : mods_) {
if ( !util::contains(con, i) ) {
newmods.push_back(i);
}
Expand All @@ -627,7 +627,7 @@ bool manager::change_era(const std::string& id)
}

std::vector<std::string> compatible;
BOOST_FOREACH (const config& i, depinfo_.child_range("scenario")) {
for (const config& i : depinfo_.child_range("scenario")) {
if (!conflicts(era, elem(i["id"], "scenario"))) {
compatible.push_back(i["id"]);
}
Expand All @@ -652,10 +652,10 @@ bool manager::change_modifications
{
// Checking if the selected combination of mods is valid at all
std::vector<std::string> filtered;
BOOST_FOREACH (const std::string& i, modifications) {
for (const std::string& i : modifications) {
bool ok = true;
elem ei(i, "modification");
BOOST_FOREACH (const std::string& j, filtered) {
for (const std::string& j : filtered) {
ok = ok && !conflicts(ei, elem(j, "modification"));
}

Expand All @@ -674,10 +674,10 @@ bool manager::change_modifications
// Checking if the currently selected era is compatible with the set
// modifications, and changing era if necessary
std::vector<std::string> compatible;
BOOST_FOREACH (const config& c, depinfo_.child_range("era")) {
for (const config& c : depinfo_.child_range("era")) {
elem era(c["id"], "era");
bool ok = true;
BOOST_FOREACH (const std::string& s, mods_) {
for (const std::string& s : mods_) {
ok = ok && !conflicts(era, elem(s, "modification"));
}

Expand Down Expand Up @@ -711,10 +711,10 @@ bool manager::change_modifications

// Checking if the currently selected scenario is compatible with
// the set modifications, and changing scenario if necessary
BOOST_FOREACH (const config& c, depinfo_.child_range("scenario")) {
for (const config& c : depinfo_.child_range("scenario")) {
elem scen(c["id"], "scenario");
bool ok = true;
BOOST_FOREACH (const std::string& s, mods_) {
for (const std::string& s : mods_) {
ok = ok && !conflicts(scen, elem(s, "modification"));
}

Expand Down
5 changes: 2 additions & 3 deletions src/gui/core/canvas.cpp
Expand Up @@ -30,7 +30,6 @@
#include "gui/widgets/helper.hpp"
#include "sdl/rect.hpp"
#include "text.hpp"
#include "utils/foreach.hpp"
#include "video.hpp"
#include "wml_exception.hpp"

Expand Down Expand Up @@ -1524,7 +1523,7 @@ void tcanvas::parse_cfg(const config& cfg)
log_scope2(log_gui_parse, "Canvas: parsing config.");
shapes_.clear();

FOREACH(const AUTO & shape, cfg.all_children_range())
for(const auto & shape : cfg.all_children_range())
{
const std::string& type = shape.key;
const config& data = shape.cfg;
Expand All @@ -1544,7 +1543,7 @@ void tcanvas::parse_cfg(const config& cfg)
} else if(type == "pre_commit") {

/* note this should get split if more preprocessing is used. */
FOREACH(const AUTO & function, data.all_children_range())
for(const auto & function : data.all_children_range())
{

if(function.key == "blur") {
Expand Down
9 changes: 4 additions & 5 deletions src/gui/core/event/handler.cpp
Expand Up @@ -23,7 +23,6 @@
#include "gui/widgets/widget.hpp"
#include "gui/widgets/window.hpp"
#include "hotkey/hotkey_item.hpp"
#include "utils/foreach.hpp"
#include "video.hpp"
#include "serialization/unicode_cast.hpp"

Expand Down Expand Up @@ -470,7 +469,7 @@ void thandler::disconnect(tdispatcher* dispatcher)
}

/***** Set proper state for the other dispatchers. *****/
FOREACH(AUTO dispatcher, dispatchers_)
for(auto dispatcher : dispatchers_)
{
dynamic_cast<twidget&>(*dispatcher).set_is_dirty(true);
}
Expand All @@ -490,7 +489,7 @@ void thandler::disconnect(tdispatcher* dispatcher)

void thandler::activate()
{
FOREACH(AUTO dispatcher, dispatchers_)
for(auto dispatcher : dispatchers_)
{
dispatcher->fire(
SDL_ACTIVATE, dynamic_cast<twidget&>(*dispatcher), nullptr);
Expand All @@ -514,7 +513,7 @@ void thandler::draw(const bool force)
*
* For now we use a hack, but would be nice to rewrite it for 1.9/1.11.
*/
FOREACH(AUTO dispatcher, dispatchers_)
for(auto dispatcher : dispatchers_)
{
if(!first) {
/*
Expand Down Expand Up @@ -542,7 +541,7 @@ void thandler::video_resize(const tpoint& new_size)
{
DBG_GUI_E << "Firing: " << SDL_VIDEO_RESIZE << ".\n";

FOREACH(AUTO dispatcher, dispatchers_)
for(auto dispatcher : dispatchers_)
{
dispatcher->fire(SDL_VIDEO_RESIZE,
dynamic_cast<twidget&>(*dispatcher),
Expand Down

0 comments on commit 982394f

Please sign in to comment.