Update miscutils to support member pointer to a variable defined in the base when passing in a derived type

develop
20k 2023-01-21 19:15:28 +00:00
parent 3024c4a0df
commit 9054efd7c8
2 changed files with 6 additions and 6 deletions

@ -167,8 +167,8 @@ int linear_index(const std::vector<CT*> &vec, FT CT::*field, FT key)
return -1; return -1;
} }
template <typename CT, typename FT> template <typename CT, typename FT, typename MT>
int binsearch_index(const std::vector<CT*> &vec, FT CT::*field, FT key, bool exact = true) int binsearch_index(const std::vector<CT*> &vec, FT MT::*field, FT key, bool exact = true)
{ {
// Returns the index of the value >= the key // Returns the index of the value >= the key
int min = -1, max = (int)vec.size(); int min = -1, max = (int)vec.size();
@ -245,8 +245,8 @@ unsigned insert_into_vector(std::vector<FT> &vec, FT key, bool *inserted = NULL)
return pos; return pos;
} }
template<typename CT, typename FT> template<typename CT, typename FT, typename MT>
unsigned insert_into_vector(std::vector<CT*> &vec, FT CT::*field, CT *obj, bool *inserted = NULL) unsigned insert_into_vector(std::vector<CT*> &vec, FT MT::*field, CT *obj, bool *inserted = NULL)
{ {
unsigned pos = (unsigned)binsearch_index(vec, field, obj->*field, false); unsigned pos = (unsigned)binsearch_index(vec, field, obj->*field, false);
bool to_ins = (pos >= vec.size() || vec[pos] != obj); bool to_ins = (pos >= vec.size() || vec[pos] != obj);

@ -186,7 +186,7 @@ static void zone_into_building_unidir(df::building* bld, df::building_civzonest*
return; return;
} }
insert_into_vector<df::building_civzonest>(bld->relations, &df::building_civzonest::id, zone); insert_into_vector(bld->relations, &df::building_civzonest::id, zone);
} }
static bool is_suitable_building_for_zoning(df::building* bld) static bool is_suitable_building_for_zoning(df::building* bld)
@ -1344,7 +1344,7 @@ static void delete_civzone_squad_links(df::building* bld)
//if this is null, something has gone just *terribly* wrong //if this is null, something has gone just *terribly* wrong
if (squad) if (squad)
{ {
for (int i=0; i < squad->rooms.size(); i++) for (int i=0; i < (int)squad->rooms.size(); i++)
{ {
if (squad->rooms[i]->building_id == bld->id) if (squad->rooms[i]->building_id == bld->id)
{ {