I’m trying to do this:
struct A
{
virtual int f() const { return 0; }
};
template <typename T>
struct B : A
{
template <typename U = T,
typename std::enable_if<...some condition involving U...>::type>
int f() const { return 1; }
};
Caveat, I can’t inherit class templates (use static overrides). Is this sort of construct allowed and can the template member B::f() override the member A::f()?
Try this:
where we have two versions of
B<T>, one for which the condition is true (theenable_ifone), one for which the condition is false (the default one).If you wanted to be able to reuse your default
Bimplementation, you could even do this:where we inherit from the "false" case in the "true" case. But that is a bit dirty to me — I’d rather put the common implementation in some third spot (
B_impl) rather than that hack. (That also lets you static assert that the second argument isvoidin the first case ofB).