Added a compile time check for MAX_SIZE

Compiler may warn if MAX_SIZE value overflows by itself but this checks
gives a more verbose warning
This commit is contained in:
Steffen Gaisser 2020-09-30 12:50:52 +02:00
parent 5340b9c58e
commit ecc4bdf11a
1 changed files with 3 additions and 1 deletions

View File

@ -2,11 +2,13 @@
#define FIXEDARRAYLIST_H_
#include "ArrayList.h"
#include <cmath>
/**
* \ingroup container
*/
template<typename T, uint32_t MAX_SIZE, typename count_t = uint8_t>
template<typename T, size_t MAX_SIZE, typename count_t = uint8_t>
class FixedArrayList: public ArrayList<T, count_t> {
static_assert(MAX_SIZE <= (pow(2,sizeof(count_t)*8)-1), "count_t is not large enough to hold MAX_SIZE");
private:
T data[MAX_SIZE];
public: