diff --git a/src/openvic-simulation/population/PopIdInProvince.hpp b/src/openvic-simulation/population/PopIdInProvince.hpp index c9b02ed0..6471f55a 100644 --- a/src/openvic-simulation/population/PopIdInProvince.hpp +++ b/src/openvic-simulation/population/PopIdInProvince.hpp @@ -5,15 +5,19 @@ #include #include +#include #include namespace OpenVic { - struct pop_id_in_province_t : type_safe::strong_typedef, + struct pop_id_in_province_t : type_safe::strong_typedef, type_safe::strong_typedef_op::equality_comparison, type_safe::strong_typedef_op::relational_comparison, type_safe::strong_typedef_op::integer_arithmetic { using strong_typedef::strong_typedef; + constexpr pop_id_in_province_t(const std::size_t i) + : pop_id_in_province_t(type_safe::narrow_cast(i)) {} \ + constexpr bool is_null() const { return type_safe::get(*this) == 0; } constexpr bool operator!() const { return is_null(); } }; @@ -23,8 +27,8 @@ namespace std { struct hash : type_safe::hashable {}; } template<> -struct fmt::formatter : fmt::formatter { +struct fmt::formatter : fmt::formatter { fmt::format_context::iterator format(OpenVic::pop_id_in_province_t const& value, fmt::format_context& ctx) const { - return fmt::formatter::format(type_safe::get(value), ctx); + return fmt::formatter::format(type_safe::get(value), ctx); } }; \ No newline at end of file diff --git a/src/openvic-simulation/types/TypedIndices.hpp b/src/openvic-simulation/types/TypedIndices.hpp index a17451ed..2bee8b4a 100644 --- a/src/openvic-simulation/types/TypedIndices.hpp +++ b/src/openvic-simulation/types/TypedIndices.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #define TYPED_INDEX_CUSTOM(name, base_type) \ @@ -15,6 +16,7 @@ type_safe::strong_typedef_op::relational_comparison, \ type_safe::strong_typedef_op::integer_arithmetic { \ using strong_typedef::strong_typedef; \ + constexpr name(const std::size_t i) : name(type_safe::narrow_cast(i)) {} \ }; \ } \ namespace std { \ @@ -27,7 +29,7 @@ return fmt::formatter::format(type_safe::get(value), ctx); \ } \ }; -#define TYPED_INDEX(name) TYPED_INDEX_CUSTOM(name, std::size_t) +#define TYPED_INDEX(name) TYPED_INDEX_CUSTOM(name, std::uint16_t) TYPED_INDEX(bookmark_index_t) TYPED_INDEX(building_type_index_t)