Suppose I have a template function and two classes
class animal { } class person { } template void foo() { if (T is animal) { kill();
In C++17, we can use variants.
To use std::variant, you need to include the header:
std::variant
#include
After that, you may add std::variant in your code like this:
using Type = std::variant; template void foo(Type type) { if (std::is_same_v) { // Do stuff... } else { // Do stuff... } }