Suppose I have a template function and two classes
class animal {
}
class person {
}
template
void foo() {
if (T is animal) {
kill();
You can specialize your templates based on what's passed into their parameters like this:
template <> void foo {
}
Note that this creates an entirely new function based on the type that's passed as T
. This is usually preferable as it reduces clutter and is essentially the reason we have templates in the first place.