This question comes from this one:
c++ pass array to function question
but since the OP accepted an answer I guess nobody will read it now.
I tried t
Array decay doesn't just happen -- it only happens when the program would fail to compile without it. When you pass an array by reference, there simply is no need for decay to kick in.
Note that the function template can also be written without dividing ugly sizeof
expressions:
template
std::size_t size_of_array(T (&array)[N])
{
return N;
}
When a client calls size_of_array
, T
and N
are automatically deduced by the template machinery.