Skip to content

Commit 97dc5bc

Browse files
committed
Fix lambda function pointer and add IsValidArgument
1 parent a3ba714 commit 97dc5bc

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

src/openvic-simulation/scripts/Condition.cpp

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -378,34 +378,36 @@ static bool _parse_condition_node_special_callback_country(
378378
return false;
379379
}
380380

381+
template<typename T>
382+
concept IsValidArgument =
383+
// Value arguments
384+
std::same_as<T, bool> || std::same_as<T, std::string> || std::same_as<T, integer_t> ||
385+
std::same_as<T, fixed_point_t> ||
386+
387+
// Game object arguments
388+
std::same_as<T, CountryDefinition const*> || std::same_as<T, ProvinceDefinition const*> ||
389+
std::same_as<T, GoodDefinition const*> || std::same_as<T, Continent const*> || std::same_as<T, BuildingType const*> ||
390+
std::same_as<T, Issue const*> || std::same_as<T, WargoalType const*> || std::same_as<T, PopType const*> ||
391+
std::same_as<T, CultureGroup const*> || std::same_as<T, Culture const*> || std::same_as<T, Religion const*> ||
392+
std::same_as<T, GovernmentType const*> || std::same_as<T, Ideology const*> || std::same_as<T, Reform const*> ||
393+
std::same_as<T, NationalValue const*> || std::same_as<T, Invention const*> ||
394+
std::same_as<T, TechnologySchool const*> || std::same_as<T, Crime const*> || std::same_as<T, Region const*> ||
395+
std::same_as<T, TerrainType const*> || std::same_as<T, Strata const*> ||
396+
397+
// Multi-value arguments
398+
std::same_as<T, std::pair<PopType const*, fixed_point_t>> || std::same_as<T, std::pair<bool, bool>> ||
399+
std::same_as<T, std::pair<Ideology const*, fixed_point_t>> || std::same_as<T, std::vector<PopType const*>> ||
400+
std::same_as<T, std::pair<std::string, fixed_point_t>>;
401+
381402
// ALLOWED_SCOPES is a bitfield indicating valid values of current_scope, as well as whether the value is allowed to be
382403
// THIS or FROM corresponding to the special argument types this_argument_t and from_argument_t respectively.
383-
template<typename T, scope_type_t ALLOWED_SCOPES = scope_type_t::ALL_SCOPES, special_callback_t SPECIAL_CALLBACK = nullptr>
404+
template<
405+
IsValidArgument T, scope_type_t ALLOWED_SCOPES = scope_type_t::ALL_SCOPES, special_callback_t SPECIAL_CALLBACK = nullptr
406+
>
384407
static bool _parse_condition_node_value_callback(
385408
Condition const& condition, DefinitionManager const& definition_manager, scope_type_t current_scope,
386409
scope_type_t this_scope, scope_type_t from_scope, ast::NodeCPtr node, callback_t<argument_t&&> callback
387410
) {
388-
static_assert(
389-
// Value arguments
390-
std::same_as<T, bool> || std::same_as<T, std::string> || std::same_as<T, integer_t> ||
391-
std::same_as<T, fixed_point_t> ||
392-
393-
// Game object arguments
394-
std::same_as<T, CountryDefinition const*> || std::same_as<T, ProvinceDefinition const*> ||
395-
std::same_as<T, GoodDefinition const*> || std::same_as<T, Continent const*> || std::same_as<T, BuildingType const*> ||
396-
std::same_as<T, Issue const*> || std::same_as<T, WargoalType const*> || std::same_as<T, PopType const*> ||
397-
std::same_as<T, CultureGroup const*> || std::same_as<T, Culture const*> || std::same_as<T, Religion const*> ||
398-
std::same_as<T, GovernmentType const*> || std::same_as<T, Ideology const*> || std::same_as<T, Reform const*> ||
399-
std::same_as<T, NationalValue const*> || std::same_as<T, Invention const*> ||
400-
std::same_as<T, TechnologySchool const*> || std::same_as<T, Crime const*> || std::same_as<T, Region const*> ||
401-
std::same_as<T, TerrainType const*> || std::same_as<T, Strata const*> ||
402-
403-
// Multi-value arguments
404-
std::same_as<T, std::pair<PopType const*, fixed_point_t>> || std::same_as<T, std::pair<bool, bool>> ||
405-
std::same_as<T, std::pair<Ideology const*, fixed_point_t>> || std::same_as<T, std::vector<PopType const*>> ||
406-
std::same_as<T, std::pair<std::string, fixed_point_t>>
407-
);
408-
409411
using enum scope_type_t;
410412

411413
// if (!share_scope_type(current_scope, ALLOWED_SCOPES & ALL_SCOPES)) {
@@ -2687,7 +2689,7 @@ bool ConditionManager::setup_conditions(DefinitionManager const& definition_mana
26872689
"has_building",
26882690
_parse_condition_node_value_callback<
26892691
BuildingType const*, PROVINCE,
2690-
[](
2692+
+[](
26912693
Condition const& condition, DefinitionManager const& definition_manager, callback_t<argument_t&&> callback,
26922694
std::string_view str, bool& ret
26932695
) -> bool {

0 commit comments

Comments
 (0)