From c377c4740d504bdd7688865698bea9a06dd157cb Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sun, 7 Apr 2024 15:54:24 +0200 Subject: [PATCH] Codechange: replace cpp_lengthof with safe alternatives --- src/industry_gui.cpp | 4 ++-- src/newgrf_storage.h | 2 +- src/stdafx.h | 8 -------- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index a5e306fd24..4f2762f253 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -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); +static_assert(MAX_CARGOES >= std::tuple_size_v); Dimension CargoesField::legend; ///< Dimension of the legend blob. Dimension CargoesField::cargo_border; ///< Dimensions of border between cargo lines and industry boxes. diff --git a/src/newgrf_storage.h b/src/newgrf_storage.h index cad016d691..3d5ab0ac04 100644 --- a/src/newgrf_storage.h +++ b/src/newgrf_storage.h @@ -206,6 +206,6 @@ struct PersistentStorage : PersistentStorageArray, PersistentStora } }; -static_assert(cpp_lengthof(OldPersistentStorage, storage) <= cpp_lengthof(PersistentStorage, storage)); +static_assert(std::tuple_size_v <= std::tuple_size_v); #endif /* NEWGRF_STORAGE_H */ diff --git a/src/stdafx.h b/src/stdafx.h index 96b740fa4a..3081beafe5 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -301,14 +301,6 @@ char (&ArraySizeHelper(T (&array)[N]))[N]; */ #define cpp_sizeof(base, variable) (sizeof(std::declval().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__)