Skip to content

Commit

Permalink
Deployed structured bindings
Browse files Browse the repository at this point in the history
This doesn't touch cases where `std::tie` was used with `std::ignore`, since there isn't a way to
ignore a variable in structured bindings and choosing a random variable name might trigger unused
variable warnings on CI (will have to confirm that, though).
  • Loading branch information
Vultraz committed Jan 17, 2021
1 parent f91f02b commit 4b80338
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 69 deletions.
5 changes: 1 addition & 4 deletions src/actions/create.cpp
Expand Up @@ -630,11 +630,8 @@ place_recruit_result place_recruit(unit_ptr u, const map_location &recruit_locat
find_recruit_leader(u->side(), recruit_location, recruited_from);
u->set_location(recruit_location);

unit_map::unit_iterator new_unit_itor;
bool success = false;

// Add the unit to the board.
std::tie(new_unit_itor, success) = resources::gameboard->units().insert(u);
auto [new_unit_itor, success] = resources::gameboard->units().insert(u);
assert(success);

map_location current_loc = recruit_location;
Expand Down
17 changes: 3 additions & 14 deletions src/actions/move.cpp
Expand Up @@ -514,10 +514,7 @@ namespace { // Private helpers for move_unit()
move_it_->anim_comp().invalidate(disp);

// Attempt actually moving. Fails if *step_to is occupied.
unit_map::unit_iterator unit_it;
bool success = false;

std::tie(unit_it, success) = resources::gameboard->units().move(*move_loc_, *step_to);
auto [unit_it, success] = resources::gameboard->units().move(*move_loc_, *step_to);

if(success) {
// Update the moving unit.
Expand Down Expand Up @@ -891,11 +888,7 @@ namespace { // Private helpers for move_unit()
// Make sure this hex is drawn correctly.
disp.invalidate(hex);
// Fire sighted events.

bool wml_undo_blocked = false;
bool wml_move_aborted = false;

std::tie(wml_undo_blocked, wml_move_aborted) = actor_sighted(*ambusher, &sight_cache);
auto [wml_undo_blocked, wml_move_aborted] = actor_sighted(*ambusher, &sight_cache);
// TODO: should we call post_wml ?
wml_move_aborted_ |= wml_move_aborted;
wml_undo_disabled_ |= wml_undo_blocked;
Expand Down Expand Up @@ -1000,11 +993,7 @@ namespace { // Private helpers for move_unit()
// Finish animating.
animator.finish(move_it_.get_shared_ptr());
// Check for the moving unit being seen.

bool wml_undo_blocked = false;
bool wml_move_aborted = false;

std::tie(wml_undo_blocked, wml_move_aborted) = actor_sighted(*move_it_, &not_seeing);
auto [wml_undo_blocked, wml_move_aborted] = actor_sighted(*move_it_, &not_seeing);
// TODO: should we call post_wml ?
wml_move_aborted_ |= wml_move_aborted;
wml_undo_disabled_ |= wml_undo_blocked;
Expand Down
10 changes: 2 additions & 8 deletions src/ai/simulated_actions.cpp
Expand Up @@ -98,11 +98,8 @@ bool simulated_move(int side, const map_location& from, const map_location& to,
{
LOG_AI_SIM_ACTIONS << "Simulated move" << std::endl;

unit_map::unit_iterator move_unit;
bool success = false;

// In simulation, AI should not know if there is a enemy's ambusher.
std::tie(move_unit, success) = resources::gameboard->units().move(from, to);
auto [move_unit, success] = resources::gameboard->units().move(from, to);

if(!success) {
// This happened because in some CAs like get_village_phase and move_leader_to_keep phase,
Expand Down Expand Up @@ -221,10 +218,7 @@ void helper_place_unit(const unit& u, const map_location& loc){
new_unit->heal_fully();
new_unit->set_location(loc);

unit_map::unit_iterator new_unit_itor;
bool success = false;

std::tie(new_unit_itor, success) = resources::gameboard->units().insert(new_unit);
auto [new_unit_itor, success] = resources::gameboard->units().insert(new_unit);
assert(success);

if(resources::gameboard->map().is_village(loc)){
Expand Down
3 changes: 1 addition & 2 deletions src/attack_prediction.cpp
Expand Up @@ -875,8 +875,7 @@ void prob_matrix::clear()
continue;
}

decltype(used_rows_[p].begin()) first_row, last_row;
std::tie(first_row, last_row) = std::minmax_element(used_rows_[p].begin(), used_rows_[p].end());
auto [first_row, last_row] = std::minmax_element(used_rows_[p].begin(), used_rows_[p].end());
for(unsigned int r = *first_row; r <= *last_row; ++r) {
for(unsigned int c = 0u; c < cols_; ++c) {
plane_[p][r * cols_ + c] = 0.0;
Expand Down
5 changes: 1 addition & 4 deletions src/formula/formula.cpp
Expand Up @@ -175,10 +175,7 @@ formula::formula(const std::string& text, function_symbol_table* symbols)
std::string str = std::string(tokens.back().begin, tokens.back().end);
files.emplace_back(str , 1);

std::set<std::string>::iterator pos;
bool success;

std::tie(pos, success) = filenames.insert(str);
auto [pos, success] = filenames.insert(str);

if(success) {
filenames_it = pos;
Expand Down
5 changes: 1 addition & 4 deletions src/game_events/wmi_manager.cpp
Expand Up @@ -204,11 +204,8 @@ void wmi_manager::to_config(config& cfg) const
*/
void wmi_manager::set_item(const std::string& id, const vconfig& menu_item)
{
auto iter = wml_menu_items_.begin();
bool success;

// First, try to insert a brand new menu item.
std::tie(iter, success) = wml_menu_items_.emplace(id, std::make_shared<wml_menu_item>(id, menu_item));
auto [iter, success] = wml_menu_items_.emplace(id, std::make_shared<wml_menu_item>(id, menu_item));

// If an entry already exists, reset it.
if(!success) {
Expand Down
3 changes: 1 addition & 2 deletions src/gui/dialogs/attack_predictions.cpp
Expand Up @@ -298,8 +298,7 @@ void attack_predictions::draw_hp_graph(drawing& hp_graph, const combatant_data&
for(const auto& probability : get_hitpoint_probabilities(attacker.combatant_.hp_dist)) {

// Get the HP and probability.
int hp; double prob;
std::tie(hp, prob) = probability;
auto [hp, prob] = probability;

color_t row_color;

Expand Down
5 changes: 1 addition & 4 deletions src/gui/dialogs/preferences_dialog.cpp
Expand Up @@ -242,10 +242,7 @@ void preferences_dialog::add_friend_list_entry(const bool is_friend, text_box& t
username = username.substr(0, pos);
}

acquaintance* entry = nullptr;
bool added_new;

std::tie(entry, added_new) = add_acquaintance(username, (is_friend ? "friend": "ignore"), reason);
auto [entry, added_new] = add_acquaintance(username, (is_friend ? "friend": "ignore"), reason);

if(!entry) {
gui2::show_transient_message(_("Error"), _("Invalid username"), "", false, false, true);
Expand Down
3 changes: 1 addition & 2 deletions src/gui/widgets/settings.cpp
Expand Up @@ -56,8 +56,7 @@ void update_screen_size_variables()
screen_width = rect.w;
screen_height = rect.h;

float scalew, scaleh;
std::tie(scalew, scaleh) = vid.get_dpi_scale_factor();
auto [scalew, scaleh] = vid.get_dpi_scale_factor();
float avgscale = (scalew + scaleh)/2;
screen_pitch_microns = MICRONS_PER_INCH / (avgscale * MAGIC_DPI_MATCH_VIDEO);

Expand Down
5 changes: 1 addition & 4 deletions src/picture.cpp
Expand Up @@ -1018,10 +1018,7 @@ bool exists(const image::locator& i_locator)

// The insertion will fail if there is already an element in the cache
// and this will point to the existing element.
auto iter = image_existence_map.begin();
bool success;

std::tie(iter, success) = image_existence_map.emplace(i_locator.get_filename(), false);
auto [iter, success] = image_existence_map.emplace(i_locator.get_filename(), false);

bool& cache = iter->second;
if(success) {
Expand Down
6 changes: 1 addition & 5 deletions src/preferences/game.cpp
Expand Up @@ -235,11 +235,7 @@ std::pair<preferences::acquaintance*, bool> add_acquaintance(
}

preferences::acquaintance new_entry(nick, mode, notes);

acquaintances_map::iterator iter;
bool success;

std::tie(iter, success) = acquaintances.emplace(nick, new_entry);
auto [iter, success] = acquaintances.emplace(nick, new_entry);

if(!success) {
iter->second = new_entry;
Expand Down
10 changes: 2 additions & 8 deletions src/scripting/lua_unit.cpp
Expand Up @@ -74,10 +74,7 @@ unit_ptr lua_unit::get_shared() const
bool lua_unit::put_map(const map_location &loc)
{
if (ptr) {
unit_map::unit_iterator unit_it;
bool success = false;

std::tie(unit_it, success) = resources::gameboard->units().replace(loc, ptr);
auto [unit_it, success] = resources::gameboard->units().replace(loc, ptr);

if(success) {
ptr.reset();
Expand Down Expand Up @@ -530,10 +527,7 @@ static int impl_unit_set(lua_State *L)
return luaL_argerror(L, 2, err_msg.c_str());
}

unit_map::iterator unit_iterator = gb->units().end();
bool success = false;

std::tie(unit_iterator, success) = gb->units().move(src, dst);
auto [unit_iterator, success] = gb->units().move(src, dst);

if(success) {
unit_iterator->anim_comp().set_standing();
Expand Down
6 changes: 2 additions & 4 deletions src/tests/test_formula_timespan.cpp
Expand Up @@ -52,16 +52,14 @@ typedef std::tuple<

inline time_t gen_as_time_t(const time_detailed& params)
{
time_t sec, min, hr, day, wk, mo, yr;
std::tie(sec, min, hr, day, wk, mo, yr) = params;
auto [sec, min, hr, day, wk, mo, yr] = params;

return YEAR*yr + MONTH*mo + WEEK*wk + DAY*day + HOUR*hr + MIN*min + SEC*sec;
}

inline std::string gen_as_str(const time_detailed& params)
{
time_t sec, min, hr, day, wk, mo, yr;
std::tie(sec, min, hr, day, wk, mo, yr) = params;
auto [sec, min, hr, day, wk, mo, yr] = params;

std::vector<t_string> bits;
std::string res;
Expand Down
6 changes: 2 additions & 4 deletions src/video.cpp
Expand Up @@ -299,8 +299,7 @@ SDL_Rect CVideo::screen_area(bool as_pixels) const

// Then convert the dimensions into screen coordinates, if applicable.
if(!as_pixels) {
float scale_x, scale_y;
std::tie(scale_x, scale_y) = get_dpi_scale_factor();
auto [scale_x, scale_y] = get_dpi_scale_factor();

size.x /= scale_x;
size.y /= scale_y;
Expand Down Expand Up @@ -464,8 +463,7 @@ std::vector<point> CVideo::get_available_resolutions(const bool include_current)

#if 0
// DPI scale factor.
float scale_h, scale_v;
std::tie(scale_h, scale_v) = get_dpi_scale_factor();
auto [scale_h, scale_v] = get_dpi_scale_factor();
#endif

// The maximum size to which this window can be set. For some reason this won't
Expand Down

0 comments on commit 4b80338

Please sign in to comment.