Given the following class
template <typename T>
class MyClass
{
public:
void DoSomething(const T* str) {
}
template<size_t N>
void DoSomething(const T(&str)[N]) {
}
};
Is there a way to prevent my arrays from 'decaying' to the (const char*)
overload?
The function is invoked in the following fashion but it seems to take preference to the non-templated function.
MyClass m<char>;
m.DoSomething("Beep Boop");
I've found I can invoke the templated function by explicitly providing a value for the templated argument. I would like to not do this if possible.
MyClass m<char>;
m.DoSomething<10>("Beep Boop");
Via possible duplicate link I solve this by changing the non-templated method to the following signature:
template<typename = std::enable_if< std::is_convertible<const T*, T const*>, {} >>
void DoSomething(const T* str) {
}