We have a const array of structures, something like this:
static const SettingsSuT _table [] = {{5,1}, {1,2}, {1,1} etc.};
The structure has the following:
- size_bytes:
- number of objects:
- Other metadata elements
Thus, the "total size" is size_bytes * num_items for one element. All this information is contained in a const array, available at compile time. But please note that the total size of _table is not related to the size of the EEPROM itself. _table does not reflect the EEPROM, it only describes the layout, usage, and other metadata data that we need. But you can use this metadata to determine the amount of EEPROM used.
The array simply describes the data that is stored in the external EEPROM, which has a fixed / maximum size. As you add and remove functions, the entries in the const array change. We are currently checking the total amount of data at runtime to ensure that it does not exceed the size of the EEPROM.
However, we have changed many of these runtime checks to static_assert style template checks, so the build stops immediately. I am not a template expert, so I could help with that.
So the question is: how to create a template to add the size of all elements (multiplying the values ββof each element and then adding all the results), and then do static_assert and stop the assembly if they exceed the size of the magic EEPROM number. I considered a typical recursive factorial example of a template as one approach, but it cannot access the array, it requires a value of const (I think).
Thanks so much for any help,