C++. Imagine I'm putting together a class for statically sized, bounds checked array:
template<typename T, int N>
class MyArray
{
T a[N];
public:
T & operator[](int i)
{
if(i < 0 || i >= N)
OnError(); //Crash and die horribly
return a[i];
}
};
Is there a way to avoid performing a bound check at run time if the array access operator is invoked with a compile time constant as an argument?
constexproverload? If, C++20,constevalstd::arrayand itsat()method already do?std::arrayas it is won't do. The question says "imagine".