I come across the following code that returns the size of a C style array.
template <typename Type, int N>
int GetArraySize(Type (&array)[N])
{
(void) sizeof (0[array]);
return N;
}
The template part seems to have already been explained in this question .
But still I do not understand what the line utility is sizeof. Any ideas? Some suggest that you should avoid warning an unused variable, but a simpler #pragmaone can be used , right?
Also, will this piece of code be effective in any situation? Are there any restrictions?
source
share