I have one template class with init() method which have to invoke subclass method if it exists. Method init() of Base class invokes forever.
template <class T>
class Base
{
template<typename... Args>
void init(Args... args);
T subj;
explicit Base() { subj = new T(); }
}
template<typename... Args>
Base<T>::init(Args... args)
{
invoke_if_exists<&T::init,subj>(args); // <-- that moment
}
There is needed to implement invoke_if_exists template. The algorithm should be as code like that
if ( method_exists(T::init) )
{
subj->init(Args...);
}
I need it to be wrapped into template
Thank you so much.
[update]:
Let I try to explain little widely.
class Foo
{
// ... and there is no init()
};
class Right
{
void init() { ... }
/// ...
}
auto a = new Base<Foo>();
auto b = new Base<Right>();
a->init(); // there is no call for Foo::init();
b->init(); // there is correct call for Right::init();
I want to use invoke_if_exists<>
not only with init() method, it could be any.