23
Given:
template<typename T>
inline bool f( T n ) {
return n >= 0 && n <= 100;
}
When used with an unsigned type generates a warning:
unsigned n;
f( n ); // warning: comparison n >= 0 is always true
Is there any clever way not to do the comparison n >= 0 when T is an unsigned type? I tried adding a partial template specialization:
template<typename T>
inline bool f( unsigned T n ) {
return n <= 100;
}
but gcc 4.2.1 doesn't like that. (I didn't think that kind of partial template specialization would be legal anyway.)