Codechange: replace cpp_lengthof with safe alternatives

This commit is contained in:
Rubidium 2024-04-07 15:54:24 +02:00 committed by rubidium42
parent a1a01e21cf
commit c377c4740d
3 changed files with 3 additions and 11 deletions

View File

@ -2380,8 +2380,8 @@ private:
}
};
static_assert(MAX_CARGOES >= cpp_lengthof(IndustrySpec, produced_cargo));
static_assert(MAX_CARGOES >= cpp_lengthof(IndustrySpec, accepts_cargo));
static_assert(MAX_CARGOES >= std::tuple_size_v<decltype(IndustrySpec::produced_cargo)>);
static_assert(MAX_CARGOES >= std::tuple_size_v<decltype(IndustrySpec::accepts_cargo)>);
Dimension CargoesField::legend; ///< Dimension of the legend blob.
Dimension CargoesField::cargo_border; ///< Dimensions of border between cargo lines and industry boxes.

View File

@ -206,6 +206,6 @@ struct PersistentStorage : PersistentStorageArray<int32_t, 256>, PersistentStora
}
};
static_assert(cpp_lengthof(OldPersistentStorage, storage) <= cpp_lengthof(PersistentStorage, storage));
static_assert(std::tuple_size_v<decltype(OldPersistentStorage::storage)> <= std::tuple_size_v<decltype(PersistentStorage::storage)>);
#endif /* NEWGRF_STORAGE_H */

View File

@ -301,14 +301,6 @@ char (&ArraySizeHelper(T (&array)[N]))[N];
*/
#define cpp_sizeof(base, variable) (sizeof(std::declval<base>().variable))
/**
* Gets the length of an array variable within a class.
* @param base The class the variable is in.
* @param variable The array variable to get the size of.
* @return the length of the array
*/
#define cpp_lengthof(base, variable) (cpp_sizeof(base, variable) / cpp_sizeof(base, variable[0]))
/* take care of some name clashes on MacOS */
#if defined(__APPLE__)