Here is an MCVE of what I'm trying to achieve:
#include <limits>
#include <iostream>
// enable_if (I'm stuck with a c++98 compiler)
template<bool B, class T = void> struct enable_if {};
template<class T> struct enable_if<true, T> { typedef T type; };
// sfinae
template<typename T> const char*
f(typename enable_if<std::numeric_limits<T>::is_integer, T>::type t) { return "sfinae"; }
template<typename T> const char*
f(T t) { return ""; }
// test
int main()
{
std::cout << f(3) << "\n"; // returns an empty string
std::cout << f(3.0) << "\n"; // returns an empty string
}
I was expecting the call to f(3)
to return "sfinae"
. What am I doing wrong?
For the first version to be called, I have to manually call f<int>(3)
. I'm puzzled.