I have a function template that must be allow only certain types. I’ve seen other questions but they used boost and primitve types. In this case, no boost, and it’s a user defined class.
Ex:
template<typename T>
myfunc(T&)
{ ... }
template<>
myfunc(Foo&)
{
static_assert(false, "You cannot use myfunc with Foo");
}
Problem is static_assert gets called regardless of whether I call myfunc with a Foo object or not.
I just want some way for compile to stop when myfunc is called with Foo.
How can I achieve this functionality?
You can use
std::is_samefor this: