As a simple example consider the following class:
template <int N>
class A {
private:
std::array<double, N> m_vs = {};
public:
int size() {return N;}
void set_value(double d, int n=0) {m_vs[n] = d;}
double get_value(int n=0) {return m_vs[n];}
}
Let's say that we have a = A<10>()
.
I would like the compiler to throw an error if I type a.set_value(1, 20)
since it is known that this will be out of bounds, but not throw any error if I write a.set_value(1, i)
since i
could be valid.
Is it possible to get such behaviour?