Suppose I have a template function and two classes
class animal {
}
class person {
}
template<class T>
void foo() {
if (T is animal) {
kill();
}
}
How do I do the check for T is animal? I don’t want to have
something that checks during the run time. Thanks
Use
is_same:Usually, that’s a totally unworkable design, though, and you really want to specialize:
Note also that it’s unusual to have function templates with explicit (non-deduced) arguments. It’s not unheard of, but often there are better approaches.