I have a templated base class which defines some sort of default functionality which a templated derived class can overload if it wants to. This "default" functionality is implemented as variadic template functions taking any argument.
If a user fails to properly define the derived class' prototype then the base class method will unintentionally be called.
Conversely, if the writer of the derived class wishes to implement a new prototype for an existing function then the Base class will become obsolete for that function name (it won't provide generic "fallback" for other derived methods that choose not to define this particular prototype of the hook).
So... rather than ramble on I'll give an example of what I'm trying to do:
template <typename Derived>
class Base
{
template <typename... Args>
void hook1(const Args&...) // -> std::enable_if(Derived::hook1 doesn't exist)
{
// do nothing
}
template <typename... Args>
void hook2(const Args&...) // -> std::enable_if(Derived::hook2 doesn't exist)
{
// do nothing
}
// ... hook3, hook4, etc.
};
// this particular derived class overloads only hook1
class DerivedExample : public Base<DerivedExample>
{
template <typename SomeArg>
void hook1(const SomeArg& arg)
{
// do something
}
};
Clearly, those enable_if
statements don't make any sense, but they illustrate the functionality I would like to have. Is this achievable?