I typed this into a template function, just to see if it would work:
if (T==int)
and the intellisense didn\'t complain. Is this valid C++? What
Just to fit your requirement you should use typeid
operator. Then your expression would look like
if (typeid(T) == typeid(int)) {
...
}
Obvious sample to illustrate that this really works:
#include
#include
template
class AClass {
public:
static bool compare() {
return (typeid(T) == typeid(int));
}
};
void main() {
std::cout << AClass::compare() << std::endl;
std::cout << AClass::compare() << std::endl;
}
So in stdout you'll probably get:
0
1