Can someone explain to me why is this piece of code working (return size of a static array):
template<class T, size_t N>
size_t lenGood(const T (& arr) [N])
{
return N;
}
And this piece don't (decays to pointer I guess):
template<class T, size_t N>
size_t lenBad(const T arr[N])
{
return N;
}
Sample main:
int main()
{
int arr[] = { 10,11,8,5,4,4 };
auto sizeGood = lenGood(arr);
//auto sizeBad = lenBad(arr); // won't compile: no instance of function matches for argument list
return 0;
}