Update swap functions to recommended ADL-friendly format
This commit is contained in:
@@ -108,71 +108,72 @@ cParty::cParty(const cParty& other)
|
||||
}
|
||||
|
||||
cParty::cParty(cParty&& other) : cParty() {
|
||||
swap(other);
|
||||
swap(*this, other);
|
||||
}
|
||||
|
||||
cParty& cParty::operator=(cParty other) {
|
||||
swap(other);
|
||||
swap(*this, other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void cParty::swap(cParty& other) {
|
||||
std::swap(next_pc_id, other.next_pc_id);
|
||||
std::swap(age, other.age);
|
||||
std::swap(gold, other.gold);
|
||||
std::swap(food, other.food);
|
||||
std::swap(stuff_done, other.stuff_done);
|
||||
std::swap(hostiles_present, other.hostiles_present);
|
||||
std::swap(easy_mode, other.easy_mode);
|
||||
std::swap(less_wm, other.less_wm);
|
||||
std::swap(magic_ptrs, other.magic_ptrs);
|
||||
std::swap(light_level, other.light_level);
|
||||
std::swap(outdoor_corner, other.outdoor_corner);
|
||||
std::swap(i_w_c, other.i_w_c);
|
||||
std::swap(out_loc, other.out_loc);
|
||||
std::swap(town_loc, other.town_loc);
|
||||
std::swap(loc_in_sec, other.loc_in_sec);
|
||||
std::swap(town_num, other.town_num);
|
||||
std::swap(boats, other.boats);
|
||||
std::swap(horses, other.horses);
|
||||
std::swap(creature_save, other.creature_save);
|
||||
std::swap(in_boat, other.in_boat);
|
||||
std::swap(in_horse, other.in_horse);
|
||||
std::swap(out_c, other.out_c);
|
||||
std::swap(magic_store_items, other.magic_store_items);
|
||||
std::swap(store_limited_stock, other.store_limited_stock);
|
||||
std::swap(job_banks, other.job_banks);
|
||||
std::swap(imprisoned_monst, other.imprisoned_monst);
|
||||
std::swap(m_noted, other.m_noted);
|
||||
std::swap(m_seen, other.m_seen);
|
||||
std::swap(journal, other.journal);
|
||||
std::swap(special_notes, other.special_notes);
|
||||
std::swap(talk_save, other.talk_save);
|
||||
std::swap(status, other.status);
|
||||
std::swap(active_quests, other.active_quests);
|
||||
std::swap(left_at, other.left_at);
|
||||
std::swap(left_in, other.left_in);
|
||||
std::swap(direction, other.direction);
|
||||
std::swap(at_which_save_slot, other.at_which_save_slot);
|
||||
std::swap(alchemy, other.alchemy);
|
||||
std::swap(key_times, other.key_times);
|
||||
std::swap(party_event_timers, other.party_event_timers);
|
||||
std::swap(spec_items, other.spec_items);
|
||||
std::swap(total_m_killed, other.total_m_killed);
|
||||
std::swap(total_dam_done, other.total_dam_done);
|
||||
std::swap(total_xp_gained, other.total_xp_gained);
|
||||
std::swap(total_dam_taken, other.total_dam_taken);
|
||||
std::swap(scen_name, other.scen_name);
|
||||
std::swap(adven, other.adven);
|
||||
std::swap(setup, other.setup);
|
||||
std::swap(stored_items, other.stored_items);
|
||||
std::swap(summons, other.summons);
|
||||
std::swap(scen_won, other.scen_won);
|
||||
std::swap(scen_played, other.scen_played);
|
||||
std::swap(campaign_flags, other.campaign_flags);
|
||||
std::swap(pointers, other.pointers);
|
||||
for(size_t i = 0; i < adven.size(); i++) {
|
||||
std::swap(adven[i], other.adven[i]);
|
||||
void swap(cParty& lhs, cParty& rhs) {
|
||||
using std::swap;
|
||||
swap(lhs.next_pc_id, rhs.next_pc_id);
|
||||
swap(lhs.age, rhs.age);
|
||||
swap(lhs.gold, rhs.gold);
|
||||
swap(lhs.food, rhs.food);
|
||||
swap(lhs.stuff_done, rhs.stuff_done);
|
||||
swap(lhs.hostiles_present, rhs.hostiles_present);
|
||||
swap(lhs.easy_mode, rhs.easy_mode);
|
||||
swap(lhs.less_wm, rhs.less_wm);
|
||||
swap(lhs.magic_ptrs, rhs.magic_ptrs);
|
||||
swap(lhs.light_level, rhs.light_level);
|
||||
swap(lhs.outdoor_corner, rhs.outdoor_corner);
|
||||
swap(lhs.i_w_c, rhs.i_w_c);
|
||||
swap(lhs.out_loc, rhs.out_loc);
|
||||
swap(lhs.town_loc, rhs.town_loc);
|
||||
swap(lhs.loc_in_sec, rhs.loc_in_sec);
|
||||
swap(lhs.town_num, rhs.town_num);
|
||||
swap(lhs.boats, rhs.boats);
|
||||
swap(lhs.horses, rhs.horses);
|
||||
swap(lhs.creature_save, rhs.creature_save);
|
||||
swap(lhs.in_boat, rhs.in_boat);
|
||||
swap(lhs.in_horse, rhs.in_horse);
|
||||
swap(lhs.out_c, rhs.out_c);
|
||||
swap(lhs.magic_store_items, rhs.magic_store_items);
|
||||
swap(lhs.store_limited_stock, rhs.store_limited_stock);
|
||||
swap(lhs.job_banks, rhs.job_banks);
|
||||
swap(lhs.imprisoned_monst, rhs.imprisoned_monst);
|
||||
swap(lhs.m_noted, rhs.m_noted);
|
||||
swap(lhs.m_seen, rhs.m_seen);
|
||||
swap(lhs.journal, rhs.journal);
|
||||
swap(lhs.special_notes, rhs.special_notes);
|
||||
swap(lhs.talk_save, rhs.talk_save);
|
||||
swap(lhs.status, rhs.status);
|
||||
swap(lhs.active_quests, rhs.active_quests);
|
||||
swap(lhs.left_at, rhs.left_at);
|
||||
swap(lhs.left_in, rhs.left_in);
|
||||
swap(lhs.direction, rhs.direction);
|
||||
swap(lhs.at_which_save_slot, rhs.at_which_save_slot);
|
||||
swap(lhs.alchemy, rhs.alchemy);
|
||||
swap(lhs.key_times, rhs.key_times);
|
||||
swap(lhs.party_event_timers, rhs.party_event_timers);
|
||||
swap(lhs.spec_items, rhs.spec_items);
|
||||
swap(lhs.total_m_killed, rhs.total_m_killed);
|
||||
swap(lhs.total_dam_done, rhs.total_dam_done);
|
||||
swap(lhs.total_xp_gained, rhs.total_xp_gained);
|
||||
swap(lhs.total_dam_taken, rhs.total_dam_taken);
|
||||
swap(lhs.scen_name, rhs.scen_name);
|
||||
swap(lhs.adven, rhs.adven);
|
||||
swap(lhs.setup, rhs.setup);
|
||||
swap(lhs.stored_items, rhs.stored_items);
|
||||
swap(lhs.summons, rhs.summons);
|
||||
swap(lhs.scen_won, rhs.scen_won);
|
||||
swap(lhs.scen_played, rhs.scen_played);
|
||||
swap(lhs.campaign_flags, rhs.campaign_flags);
|
||||
swap(lhs.pointers, rhs.pointers);
|
||||
for(size_t i = 0; i < lhs.adven.size(); i++) {
|
||||
swap(*lhs.adven[i], *rhs.adven[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -237,7 +237,7 @@ public:
|
||||
typedef std::vector<cConvers>::iterator talkIter;
|
||||
cParty(ePartyPreset party_preset = PARTY_DEFAULT);
|
||||
// Copy-and-swap
|
||||
void swap(cParty& other);
|
||||
friend void swap(cParty& lhs, cParty& rhs);
|
||||
cParty(const cParty& other);
|
||||
cParty(cParty&& other);
|
||||
cParty& operator=(cParty other);
|
||||
|
@@ -1160,34 +1160,35 @@ cPlayer::cPlayer(no_party_t, const cPlayer& other)
|
||||
{}
|
||||
|
||||
cPlayer::cPlayer(cPlayer&& other) : weap_poisoned(*this, other.weap_poisoned.slot) {
|
||||
swap(other);
|
||||
swap(*this, other);
|
||||
}
|
||||
|
||||
void cPlayer::swap(cPlayer& other) {
|
||||
void swap(cPlayer& lhs, cPlayer& rhs) {
|
||||
using std::swap;
|
||||
// Don't swap the party reference!
|
||||
std::swap(main_status, other.main_status);
|
||||
std::swap(name, other.name);
|
||||
std::swap(skills, other.skills);
|
||||
std::swap(max_health, other.max_health);
|
||||
std::swap(cur_health, other.cur_health);
|
||||
std::swap(max_sp, other.max_sp);
|
||||
std::swap(cur_sp, other.cur_sp);
|
||||
std::swap(experience, other.experience);
|
||||
std::swap(skill_pts, other.skill_pts);
|
||||
std::swap(level, other.level);
|
||||
std::swap(items, other.items);
|
||||
std::swap(equip, other.equip);
|
||||
std::swap(priest_spells, other.priest_spells);
|
||||
std::swap(mage_spells, other.mage_spells);
|
||||
std::swap(which_graphic, other.which_graphic);
|
||||
std::swap(weap_poisoned.slot, other.weap_poisoned.slot);
|
||||
std::swap(traits, other.traits);
|
||||
std::swap(race, other.race);
|
||||
std::swap(unique_id, other.unique_id);
|
||||
std::swap(last_cast, other.last_cast);
|
||||
std::swap(combat_pos, other.combat_pos);
|
||||
std::swap(parry, other.parry);
|
||||
std::swap(last_attacked, other.last_attacked);
|
||||
swap(lhs.main_status, rhs.main_status);
|
||||
swap(lhs.name, rhs.name);
|
||||
swap(lhs.skills, rhs.skills);
|
||||
swap(lhs.max_health, rhs.max_health);
|
||||
swap(lhs.cur_health, rhs.cur_health);
|
||||
swap(lhs.max_sp, rhs.max_sp);
|
||||
swap(lhs.cur_sp, rhs.cur_sp);
|
||||
swap(lhs.experience, rhs.experience);
|
||||
swap(lhs.skill_pts, rhs.skill_pts);
|
||||
swap(lhs.level, rhs.level);
|
||||
swap(lhs.items, rhs.items);
|
||||
swap(lhs.equip, rhs.equip);
|
||||
swap(lhs.priest_spells, rhs.priest_spells);
|
||||
swap(lhs.mage_spells, rhs.mage_spells);
|
||||
swap(lhs.which_graphic, rhs.which_graphic);
|
||||
swap(lhs.weap_poisoned.slot, rhs.weap_poisoned.slot);
|
||||
swap(lhs.traits, rhs.traits);
|
||||
swap(lhs.race, rhs.race);
|
||||
swap(lhs.unique_id, rhs.unique_id);
|
||||
swap(lhs.last_cast, rhs.last_cast);
|
||||
swap(lhs.combat_pos, rhs.combat_pos);
|
||||
swap(lhs.parry, rhs.parry);
|
||||
swap(lhs.last_attacked, rhs.last_attacked);
|
||||
}
|
||||
|
||||
void operator += (eMainStatus& stat, eMainStatus othr){
|
||||
|
@@ -186,7 +186,7 @@ public:
|
||||
void readFrom(const cTagFile& file);
|
||||
virtual ~cPlayer() = default;
|
||||
// Copy-and-swap
|
||||
void swap(cPlayer& other);
|
||||
friend void swap(cPlayer& lhs, cPlayer& rhs);
|
||||
cPlayer(const cPlayer& other) = delete;
|
||||
cPlayer(cPlayer&& other);
|
||||
// For now, not assignable because of an issue of how to handle the unique_id
|
||||
|
@@ -67,8 +67,9 @@ void cPopulation::assign(size_t n, const cTownperson& other, const cMonster& bas
|
||||
dudes[n].summon_time = 0;
|
||||
}
|
||||
|
||||
void cPopulation::swap(cPopulation& other) {
|
||||
std::swap(dudes, other.dudes);
|
||||
std::swap(which_town, other.which_town);
|
||||
std::swap(hostile, other.hostile);
|
||||
void swap(cPopulation& lhs, cPopulation& rhs) {
|
||||
using std::swap;
|
||||
swap(lhs.dudes, rhs.dudes);
|
||||
swap(lhs.which_town, rhs.which_town);
|
||||
swap(lhs.hostile, rhs.hostile);
|
||||
}
|
||||
|
@@ -37,7 +37,7 @@ public:
|
||||
std::deque<cCreature>::iterator end() {return dudes.end();}
|
||||
// Apparently Visual Studio needs this to work
|
||||
cPopulation& operator=(const cPopulation& other) = default;
|
||||
void swap(cPopulation& other);
|
||||
friend void swap(cPopulation& lhs, cPopulation& rhs);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -994,27 +994,28 @@ cUniverse::cUniverse(const cUniverse& other)
|
||||
}
|
||||
|
||||
cUniverse::cUniverse(cUniverse&& other) : town(*this), out(*this) {
|
||||
swap(other);
|
||||
swap(*this, other);
|
||||
}
|
||||
|
||||
cUniverse& cUniverse::operator=(cUniverse other) {
|
||||
swap(other);
|
||||
swap(*this, other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void cUniverse::swap(cUniverse& other) {
|
||||
party.swap(other.party);
|
||||
town.swap(other.town);
|
||||
out.swap(other.out);
|
||||
scenario.swap(other.scenario);
|
||||
std::swap(stored_pcs, other.stored_pcs);
|
||||
std::swap(file, other.file);
|
||||
std::swap(debug_mode, other.debug_mode);
|
||||
std::swap(ghost_mode, other.ghost_mode);
|
||||
std::swap(node_step_through, other.node_step_through);
|
||||
std::swap(cur_pc, other.cur_pc);
|
||||
std::swap(strbuf, other.strbuf);
|
||||
std::swap(extrabufs, other.extrabufs);
|
||||
void swap(cUniverse& lhs, cUniverse& rhs) {
|
||||
using std::swap;
|
||||
swap(lhs.party, rhs.party);
|
||||
swap(lhs.town, rhs.town);
|
||||
swap(lhs.out, rhs.out);
|
||||
swap(lhs.scenario, rhs.scenario);
|
||||
swap(lhs.stored_pcs, rhs.stored_pcs);
|
||||
swap(lhs.file, rhs.file);
|
||||
swap(lhs.debug_mode, rhs.debug_mode);
|
||||
swap(lhs.ghost_mode, rhs.ghost_mode);
|
||||
swap(lhs.node_step_through, rhs.node_step_through);
|
||||
swap(lhs.cur_pc, rhs.cur_pc);
|
||||
swap(lhs.strbuf, rhs.strbuf);
|
||||
swap(lhs.extrabufs, rhs.extrabufs);
|
||||
}
|
||||
|
||||
void cCurOut::copy(const cCurOut& other) {
|
||||
@@ -1022,11 +1023,10 @@ void cCurOut::copy(const cCurOut& other) {
|
||||
out_e = other.out_e;
|
||||
}
|
||||
|
||||
void cCurOut::swap(cCurOut& other) {
|
||||
cCurOut temp(univ);
|
||||
temp.copy(other);
|
||||
other.copy(*this);
|
||||
copy(temp);
|
||||
void swap(cCurOut& lhs, cCurOut& rhs) {
|
||||
using std::swap;
|
||||
swap(lhs.out, rhs.out);
|
||||
swap(lhs.out_e, rhs.out_e);
|
||||
}
|
||||
|
||||
void cCurTown::copy(const cCurTown& other) {
|
||||
@@ -1038,13 +1038,14 @@ void cCurTown::copy(const cCurTown& other) {
|
||||
fields = other.fields;
|
||||
}
|
||||
|
||||
void cCurTown::swap(cCurTown& other) {
|
||||
std::swap(cur_talk_loaded, other.cur_talk_loaded);
|
||||
std::swap(quickfire_present, other.quickfire_present);
|
||||
std::swap(belt_present, other.belt_present);
|
||||
monst.swap(other.monst);
|
||||
std::swap(items, other.items);
|
||||
fields.swap(other.fields);
|
||||
void swap(cCurTown& lhs, cCurTown& rhs) {
|
||||
using std::swap;
|
||||
swap(lhs.cur_talk_loaded, rhs.cur_talk_loaded);
|
||||
swap(lhs.quickfire_present, rhs.quickfire_present);
|
||||
swap(lhs.belt_present, rhs.belt_present);
|
||||
swap(lhs.monst, rhs.monst);
|
||||
swap(lhs.items, rhs.items);
|
||||
swap(lhs.fields, rhs.fields);
|
||||
}
|
||||
|
||||
void cUniverse::check_monst(cMonster& monst) {
|
||||
|
@@ -136,7 +136,7 @@ public:
|
||||
cCurTown& operator=(const cCurTown&& other) = delete;
|
||||
// This implements the actual copy/move.
|
||||
void copy(const cCurTown& other);
|
||||
void swap(cCurTown& other);
|
||||
friend void swap(cCurTown& lhs, cCurTown& rhs);
|
||||
};
|
||||
|
||||
class cCurOut {
|
||||
@@ -173,7 +173,7 @@ public:
|
||||
cCurOut& operator=(const cCurOut&& other) = delete;
|
||||
// This implements the actual copy/move.
|
||||
void copy(const cCurOut& other);
|
||||
void swap(cCurOut& other);
|
||||
friend void swap(cCurOut& lhs, cCurOut& rhs);
|
||||
};
|
||||
|
||||
enum eTargetType {TARG_ANY, TARG_PC, TARG_MONST};
|
||||
@@ -228,7 +228,7 @@ public:
|
||||
short difficulty_adjust() const;
|
||||
explicit cUniverse(ePartyPreset party_type = PARTY_DEFAULT);
|
||||
// Copy-and-swap
|
||||
void swap(cUniverse& other);
|
||||
friend void swap(cUniverse& lhs, cUniverse& rhs);
|
||||
cUniverse(const cUniverse& other);
|
||||
cUniverse(cUniverse&& other);
|
||||
cUniverse& operator=(cUniverse other);
|
||||
|
Reference in New Issue
Block a user