I have a template class like so:
template<typename T, unsigned int size>
class Array
{
public:
static const unsigned int SIZE = size;
// ...
private:
T data[SIZE];
};
Is there a way to add compile-time checks such that the size of an Array<T,XXXX>
never exceeds a certain value?
Like if that value was 512
, this shouldn't compile:
Array<int, 1000> arr;
This idea of C++ifiying my code is new to me, so I'm open to any guides or further learning online to help with this since I didn't even know what to google for this. Everything I tried seemed way off.