I’m trying to create a set of overloaded templates for arrays/pointers where one template will be used when the compiler knows the size of the array and the other template will be used when it doesn’t:
template <typename T, size_t SZ>
void moo(T (&arr)[SZ])
{ ... }
template <typename T>
void moo(T *ptr)
{ ... }
The problem is that when the compiler knows the size of the array, the overloads are ambiguous and the compile fails.
Is there some way to resolve the ambiguity (perhaps via SFINAE) or is this just not possible.
It is possible as it can be determined wether a template parameter is an array or not:
Combining that with
enable_if, the above can be made unambiguous. For example using Boost.TypeTraits:With references however there is no need for SFINAE at all:
Johannes brings up another option that fits the situation at hand better – using SFINAE for the problematic pointer overload instead: