To be able to check some value at compile time, this value must be used in the appropriate context. The function argument is not relevant to this context. But if you implement a template function with a non-type parameter, then this can already be done. True syntax will be different:
#include <cstdlib> template <class T, size_t N> class Vect { public: typedef unsigned int size_type; T coord[N] = {}; template <size_type I> constexpr T& get() { static_assert(I < N); return coord[I]; } }; int main() { Vect<int, 10> v; v.get<9>(); // OK v.get<10>(); // Ошибка компиляции }
Similar functionality already exists in the standard library when using std::get on std::array .