####
The following 2 c++ template functions can detect array's dimension at compile time. But they will fail when dealing with variable length array(introduced by C99).
template<typename T, int len >int capacity_of_1Darray( T(&array)[len] )
{
return len;
}
template<typename T, int l, int m>void capacity_of_2Darray(T (&array)[l][m], int &x, int &y)
{
x=l;
y=m;
The following 2 c++ template functions can detect array's dimension at compile time. But they will fail when dealing with variable length array(introduced by C99).
template<typename T, int len >int capacity_of_1Darray( T(&array)[len] )
{
return len;
}
template<typename T, int l, int m>void capacity_of_2Darray(T (&array)[l][m], int &x, int &y)
{
x=l;
y=m;
}