diff options
author | Bardur Arantsson <bardur@scientician.net> | 2016-06-20 22:49:05 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2016-06-20 22:49:05 +0200 |
commit | 145ea9e004c6014c790abb8d7b81f7f1547af3b9 (patch) | |
tree | f11869d7682a9e97a335b2baeba7458db6ff4473 | |
parent | ca3fab4c43e155494e7eddfede551f3ced7ddad0 (diff) |
Change flag_set bool conversion to 'explicit'
-rw-r--r-- | src/flag_set.hpp | 12 | ||||
-rw-r--r-- | src/monster2.cc | 6 | ||||
-rw-r--r-- | src/spells1.cc | 2 | ||||
-rw-r--r-- | src/spells2.cc | 6 | ||||
-rw-r--r-- | src/spells3.cc | 2 | ||||
-rw-r--r-- | tests/flag_set.cc | 4 |
6 files changed, 21 insertions, 11 deletions
diff --git a/src/flag_set.hpp b/src/flag_set.hpp index aa90a217..490f0daf 100644 --- a/src/flag_set.hpp +++ b/src/flag_set.hpp @@ -92,11 +92,21 @@ public: return m_data[i]; } - constexpr operator bool() const + explicit constexpr operator bool() const { return !empty(); } + constexpr bool operator == (flag_set const &other) const + { + return m_data == other.m_data; + } + + constexpr bool operator != (flag_set const &other) const + { + return !(*this == other); + } + constexpr bool bit(std::size_t i) const { assert(i < nbits); diff --git a/src/monster2.cc b/src/monster2.cc index 52b342d4..bf1d3d12 100644 --- a/src/monster2.cc +++ b/src/monster2.cc @@ -2218,9 +2218,9 @@ s16b place_monster_one(int y, int x, int r_idx, int ego, bool_ slp, int status) const bool_ good = (r_ptr->flags & RF_DROP_GOOD) ? TRUE : FALSE; const bool_ great = (r_ptr->flags & RF_DROP_GREAT) ? TRUE : FALSE; - const bool_ do_gold = (!(r_ptr->flags & RF_ONLY_ITEM)); - const bool_ do_item = (!(r_ptr->flags & RF_ONLY_GOLD)); - const bool_ do_mimic = (r_ptr->flags & RF_MIMIC); + auto const do_gold = (r_ptr->flags & RF_ONLY_ITEM).empty(); + auto const do_item = (r_ptr->flags & RF_ONLY_GOLD).empty(); + auto const do_mimic = bool(r_ptr->flags & RF_MIMIC); const int force_coin = get_coin_type(r_ptr); diff --git a/src/spells1.cc b/src/spells1.cc index 8e109a77..2b34e98c 100644 --- a/src/spells1.cc +++ b/src/spells1.cc @@ -6622,7 +6622,7 @@ bool_ project_m(int who, int r, int y, int x, int dam, int typ) if ((who > 0) && (dam > m_ptr->hp)) dam = m_ptr->hp; } - if (do_pois && (!(r_ptr->flags & RF_IM_POIS)) && (!(r_ptr->flags & SF_BR_POIS)) && hurt_monster(m_ptr)) + if (do_pois && (r_ptr->flags & RF_IM_POIS).empty() && (r_ptr->spells & SF_BR_POIS).empty() && hurt_monster(m_ptr)) { if (m_ptr->poisoned) note = " is more poisoned."; else note = " is poisoned."; diff --git a/src/spells2.cc b/src/spells2.cc index 535b03f2..c08cad97 100644 --- a/src/spells2.cc +++ b/src/spells2.cc @@ -1163,7 +1163,7 @@ void self_knowledge(FILE *fff) /* Not implemented */ if (r_ptr->flags & RF_CAN_FLY) info[i++] = "You can fly."; - if ((r_ptr->flags & RF_MORTAL) == 0) + if ((r_ptr->flags & RF_MORTAL).empty()) info[i++] = "You are immortal."; /* Not implemented */ if (r_ptr->flags & RF_NAZGUL) @@ -2506,7 +2506,7 @@ bool_ detect_monsters_normal(int rad) bool_ detect_monsters_invis(int rad) { auto predicate = [](monster_race *r_ptr) -> bool { - return (r_ptr->flags & RF_INVISIBLE); + return bool(r_ptr->flags & RF_INVISIBLE); }; if (detect_monsters_fn(rad, predicate)) @@ -2529,7 +2529,7 @@ bool_ detect_monsters_invis(int rad) void detect_monsters_orcs(int rad) { auto predicate = [](monster_race *r_ptr) -> bool { - return (r_ptr->flags & RF_ORC); + return bool(r_ptr->flags & RF_ORC); }; if (detect_monsters_fn(rad, predicate)) diff --git a/src/spells3.cc b/src/spells3.cc index 26a15541..b5a767c5 100644 --- a/src/spells3.cc +++ b/src/spells3.cc @@ -2272,7 +2272,7 @@ casting_result melkor_mind_steal() auto const r_ptr = m_ptr->race(); if ((randint(m_ptr->level) < chance) && - ((r_ptr->flags & RF_UNIQUE) == 0)) + ((r_ptr->flags & RF_UNIQUE).empty())) { p_ptr->control = target_who; m_ptr->mflag |= MFLAG_CONTROL; diff --git a/tests/flag_set.cc b/tests/flag_set.cc index 125d8a81..3abd505d 100644 --- a/tests/flag_set.cc +++ b/tests/flag_set.cc @@ -45,7 +45,7 @@ go_bandit([]() { // Setup fs_t fs = fs_t(); // Exercise - bool result = fs; + auto result = bool(fs); // Verify AssertThat(result, Equals(false)); }); @@ -54,7 +54,7 @@ go_bandit([]() { // Setup fs_t fs = fs_t::make(1, 3); // Exercise - bool result = fs; + auto result = bool(fs); // Verify AssertThat(result, Equals(true)); }); |