Skip to content

Commit 4a1efaf

Browse files
authored
Merge pull request #520 from OpenVicProject/explicit_create_empty
Explicit create empty for IndexedFlatMap
2 parents c5dfb95 + fb00a7c commit 4a1efaf

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

src/openvic-simulation/economy/production/ProductionType.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ bool ProductionType::parse_scripts(DefinitionManager const& definition_manager)
7676
return ret;
7777
}
7878

79-
ProductionTypeManager::ProductionTypeManager() :
80-
rgo_owner_sprite { 0 } {}
8179

8280
ProductionType const* ProductionTypeManager::get_good_to_rgo_production_type(GoodDefinition const& key) const {
8381
return good_to_rgo_production_type.at(key);

src/openvic-simulation/economy/production/ProductionType.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ namespace OpenVic {
110110
);
111111

112112
public:
113-
ProductionTypeManager();
113+
constexpr ProductionTypeManager()
114+
: rgo_owner_sprite { 0 },
115+
good_to_rgo_production_type { decltype(good_to_rgo_production_type)::create_empty() } {}
114116

115117
bool add_production_type(
116118
GameRulesManager const& game_rules_manager,

src/openvic-simulation/modifier/ModifierEffectCache.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,16 @@ namespace OpenVic {
344344

345345
/* Technology Effects */
346346
IndexedFlatMap_PROPERTY(TechnologyFolder, ModifierEffect const*, research_bonus_effects);
347-
ModifierEffectCache() {}
347+
constexpr ModifierEffectCache() :
348+
building_type_effects { decltype(building_type_effects)::create_empty() },
349+
good_effects { decltype(good_effects)::create_empty() },
350+
regiment_type_effects { decltype(regiment_type_effects)::create_empty() },
351+
ship_type_effects { decltype(ship_type_effects)::create_empty() },
352+
unit_terrain_effects { decltype(unit_terrain_effects)::create_empty() },
353+
rebel_org_gain_effects { decltype(rebel_org_gain_effects)::create_empty() },
354+
strata_effects { decltype(strata_effects)::create_empty() },
355+
research_bonus_effects { decltype(research_bonus_effects)::create_empty() }
356+
{}
348357

349358
public:
350359
ModifierEffectCache(ModifierEffectCache&&) = default;

src/openvic-simulation/pop/PopManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ bool PopManager::add_pop_type(
174174
static_cast<PopType const*>(nullptr),
175175
std::move(country_migration_target),
176176
std::move(migration_target),
177-
PopType::poptype_weight_map_t{},
177+
PopType::poptype_weight_map_t { PopType::poptype_weight_map_t::create_empty() },
178178
std::move(ideologies),
179179
PopType::issue_weight_map_t{}
180180
))) {

src/openvic-simulation/types/IndexedFlatMap.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,13 @@ namespace OpenVic {
166166
return true;
167167
}
168168

169+
constexpr IndexedFlatMap() : values(), keys(), min_index(0), max_index(0) {}
170+
169171
public:
172+
static constexpr IndexedFlatMap create_empty() {
173+
return {};
174+
}
175+
170176
/**
171177
* @brief Constructs an IndexedFlatMap based on a provided span of ordered and continuous keys
172178
* and a key-based generator.
@@ -221,12 +227,6 @@ namespace OpenVic {
221227
values.resize(expected_capacity);
222228
}
223229

224-
/**
225-
* @brief Default constructor, creates an empty map.
226-
* Useful for returning an invalid state on error in other operations.
227-
*/
228-
IndexedFlatMap() : values(), keys(), min_index(0), max_index(0) {}
229-
230230
/**
231231
* @brief Sets the value associated with a key using copy assignment.
232232
*/

0 commit comments

Comments
 (0)