diff --git a/src/units/abilities.cpp b/src/units/abilities.cpp index 5e269bec40f0..d0621d370977 100644 --- a/src/units/abilities.cpp +++ b/src/units/abilities.cpp @@ -587,8 +587,8 @@ bool attack_type::get_special_bool(const std::string& special, bool simple_check // If we make it to here, then either list.empty() or !simple_check. // So if the list is not empty, then this is not a simple check and // we need to check each special in the list to see if any are active. - for (std::vector::iterator i = list.begin(), i_end = list.end(); i != i_end; ++i) { - if ( special_active(**i, AFFECT_SELF) ) { + for(const config* entry : list) { + if ( special_active(*entry, AFFECT_SELF) ) { return true; } } @@ -600,8 +600,8 @@ bool attack_type::get_special_bool(const std::string& special, bool simple_check std::vector list; get_special_children(list, other_attack_->specials_, special); - for (std::vector::iterator i = list.begin(), i_end = list.end(); i != i_end; ++i) { - if ( other_attack_->special_active(**i, AFFECT_OTHER) ) { + for(const config* entry : list) { + if ( other_attack_->special_active(*entry, AFFECT_OTHER) ) { return true; } } @@ -1208,19 +1208,21 @@ effect::effect(const unit_ability_list& list, int def, bool backstab) : */ double multiplier = 1.0; double divisor = 1.0; - std::map::const_iterator e, e_end; - for (e = values_mul.begin(), e_end = values_mul.end(); e != e_end; ++e) { - multiplier *= e->second.value/100.0; - effect_list_.push_back(e->second); + + for(const auto& val : values_mul) { + multiplier *= val.second.value/100.0; + effect_list_.push_back(val.second); } - for (e = values_div.begin(), e_end = values_div.end(); e != e_end; ++e) { - divisor *= e->second.value/100.0; - effect_list_.push_back(e->second); + + for(const auto& val : values_div) { + divisor *= val.second.value/100.0; + effect_list_.push_back(val.second); } + int addition = 0; - for (e = values_add.begin(), e_end = values_add.end(); e != e_end; ++e) { - addition += e->second.value; - effect_list_.push_back(e->second); + for(const auto& val : values_add) { + addition += val.second.value; + effect_list_.push_back(val.second); } composite_value_ = int((value_set + addition) * multiplier / divisor); diff --git a/src/units/animation_component.cpp b/src/units/animation_component.cpp index f9eddb002b65..13c5da403671 100644 --- a/src/units/animation_component.cpp +++ b/src/units/animation_component.cpp @@ -31,14 +31,14 @@ const unit_animation* unit_animation_component::choose_animation(const display& // Select one of the matching animations at random std::vector options; int max_val = unit_animation::MATCH_FAIL; - for(std::vector::const_iterator i = animations_.begin(); i != animations_.end(); ++i) { - int matching = i->matches(disp,loc,second_loc,&u_,event,value,hit,attack,second_attack,swing_num); + for(const unit_animation& anim : animations_) { + int matching = anim.matches(disp,loc,second_loc,&u_,event,value,hit,attack,second_attack,swing_num); if(matching > unit_animation::MATCH_FAIL && matching == max_val) { - options.push_back(&*i); + options.push_back(&anim); } else if(matching > max_val) { max_val = matching; options.clear(); - options.push_back(&*i); + options.push_back(&anim); } } diff --git a/src/units/drawer.cpp b/src/units/drawer.cpp index e6acd9938fa3..9b329ecf25ec 100644 --- a/src/units/drawer.cpp +++ b/src/units/drawer.cpp @@ -308,8 +308,8 @@ void unit_drawer::redraw_unit (const unit & u) const } } - for(std::vector::const_iterator ov = u.overlays().begin(); ov != u.overlays().end(); ++ov) { - const surface ov_img(image::get_image(*ov, image::SCALED_TO_ZOOM)); + for(const std::string& ov : u.overlays()) { + const surface ov_img(image::get_image(ov, image::SCALED_TO_ZOOM)); if(ov_img != nullptr) { disp.drawing_buffer_add(display::LAYER_UNIT_BAR, loc, xsrc+xoff, ysrc+yoff+adjusted_params.y, ov_img); diff --git a/src/units/map.cpp b/src/units/map.cpp index a7676810be99..953ee7caa613 100644 --- a/src/units/map.cpp +++ b/src/units/map.cpp @@ -38,8 +38,8 @@ unit_map::unit_map(const unit_map& that) : umap_() , lmap_() { - for(const_unit_iterator i = that.begin(); i != that.end(); ++i) { - add(i->get_location(), *i); + for(const auto& u : that) { + add(u.get_location(), u); } } diff --git a/src/units/types.cpp b/src/units/types.cpp index cced33fde9ea..49b09079769d 100644 --- a/src/units/types.cpp +++ b/src/units/types.cpp @@ -263,9 +263,8 @@ void unit_type::build_help_index( // if num_traits is not defined, we use the num_traits from race num_traits_ = cfg_["num_traits"].to_int(race_->num_traits()); - const std::vector genders = utils::split(cfg_["gender"]); - for(std::vector::const_iterator g = genders.begin(); g != genders.end(); ++g) { - genders_.push_back(string_gender(*g)); + for(const std::string& g : utils::split(cfg_["gender"])) { + genders_.push_back(string_gender(g)); } // For simplicity in other parts of the code, we must have at least one gender. @@ -645,9 +644,9 @@ void unit_type::add_advancement(const unit_type& to_unit, int xp) // Since these are still a rare and special-purpose feature, // we assume that the unit designer knows what they're doing, // and don't block advancements that would remove a variation. - for(variations_map::iterator v = variations_.begin(); v != variations_.end(); ++v) { + for(auto& v : variations_) { LOG_CONFIG << "variation advancement: "; - v->second.add_advancement(to_unit, xp); + v.second.add_advancement(to_unit, xp); } } } @@ -1328,8 +1327,8 @@ void unit_type_data::build_all(unit_type::BUILD_STATUS status) assert(unit_cfg_ != nullptr); - for(unit_type_map::iterator u = types_.begin(), u_end = types_.end(); u != u_end; ++u) { - build_unit_type(u->second, status); + for(const auto& type : types_) { + build_unit_type(type.second, status); gui2::dialogs::loading_screen::progress(); } @@ -1338,8 +1337,8 @@ void unit_type_data::build_all(unit_type::BUILD_STATUS status) // (Currently, this could be simply a test for build_status_ == NOT_BUILT, // but to guard against future changes, use a more thorough test.) if(build_status_ < unit_type::CREATED && unit_type::CREATED <= status) { - for(unit_type_map::iterator u = types_.begin(), u_end = types_.end(); u != u_end; ++u) { - add_advancement(u->second); + for(auto& type : types_) { + add_advancement(type.second); } }