I'd like to be able to disable an overloaded operator function based on template parameters like so
template <int T>
class Foo {
int v;
template <std::enable_if_t<T == 0, int> = 0>
Foo operator-() const
{
return {-v};
}
};
But when I try to instantiate a Foo with a value that would disable the function (i.e. 1) the compiler complains
Foo<0> f0; // This compiles
Foo<1> f1; // This does not
I am not trying to invoke the disabled function but the compile complains about being unable to access it.
Any explanations of this behavior?