This is a problem I've been struggling with for a while now. The codes I have tried below are not compiling either.
The question is: How do I differentiate between a pointer and a fixed array in a function parameter?
// Concepts for the Array I have tried but not succeeded.
template <size_t length, typename type>
const unsigned int len(type arg[static length]) { return length; }
template <size_t length, typename type>
const unsigned int len(type(&)[length]) { return length; }
// This works for Arrays & Pointers
// but should be less prioritized over the function that detects the Array
template <typename type> const unsigned int len(type* arg) { return sizeof(*arg); }
I know how arrays & pointers are basically similar when passed into a function, but it asks the question: is there not a way to tell them apart?
Syntactically yes, but otherwise what other way is there?
Anyway, thanks for reading through and cheers on your response.
static lengthis not valid C++. That particular C99 feature is not available.