I would like to define a template function but disallow instantiation with a particular type. Note that in general all types are allowed and the generic template works, I just w
Consider Boost disable_if and Boost TypeTraits
Take a look at How can I write a function template for all types with a particular type trait?
This is an example:
#include
#include
template
T convert( char const * in,
typename boost::disable_if, T>::type* = 0 )
{ return T(); }
int main()
{
char const * str = "1234";
int a = convert( str );
double b = convert( str );
return 0;
}
This is the compilation error for the string
double b = convert( str );
1>.\simple_no_stlport.cpp(14) : error C2770: invalid explicit template argument(s) for 'T convert(const char *,boost::disable_if,T>::type *)' 1> .\simple_no_stlport.cpp(5) : see declaration of 'convert'