I need a very fast way to check the boundaries of an array. My current limitations are:
template<typename T>
class SmartArray {
int size;
T* array;
T &operator[](int index) {
if (index/size!=0)
throw OUT_OF_RANGE;
return array[index];
}
}
Is there a faster way to check if an index is specified from the boundaries of an array?
EDIT:
My solution creates problems with negative indices. Is there any way to fix this?
source
share