I would like to provide different implementations of a function dependant on if it is a pointer, a reference or a regular type. This is my code so far:
template<class T,
class = typename std::enable_if_t<std::is_reference<T>::value>>
void f(T && in)
{}
// This causes redefinition error
template<class T,
class = typename std::enable_if_t<std::is_pointer<T>::value>>
void f(T && in)
{}
template<class T,
class = typename std::enable_if_t<!std::is_reference<T>::value>,
class = typename std::enable_if_t<!std::is_pointer<T>::value>>
void f(T && in)
{}
The middle function causes:
12:13: error: redefinition of 'template void f(T&&)'
7:13: note: 'template void f(T&&)' previously declared here
Funnily only the first and last function together compile.
Any ideas how to fix it or simplify this code.
void f(T*),void f(T&), andvoid f(T)?void f(T&&)as not forwarding reference? I mean I could do the whole process reverse but not sure if it makes things easier.