So I've come across a problem where using function template specialization forces me to write the function in the same namespace as the function template. I cannot do this because some other code requires to define some function template within another specific namespace.
To work-around the namespace issue, I'm trying to use function overloading instead. Furthermore, these functions return value need to be constexpr, so I could not overload using a class reference, so I used a class pointer instead.
So I ended up with this:
template<class T> constexpr auto getName(T* const) { return ""; }
and then I overload them like this:
inline constexpr auto getName(int* const) { return "int"; }
This works fine and allows me to call the correct overload using a nullptr trick like this:
auto name = getName((int* const)nullptr);
My problem is it seems I am unable to overload this when the type is an array. I would like to be able to overload when the type is int[], and return the string "int[]" in that case.
Perhaps there is a better solution to avoid the namespace hell for function template specialization? I know this all stinks but I could not find a better alternative yet.
Thank you!
typeidfor this specific case.int(&)[size], with template size. do you need it?