Doesn't you code assume that there is exactly one derived class, and that the base class knows the name of it?
Re:Final features of C++17
by Kristine1975 on Saturday July 02, 2016 @07:32AM
(#12022153)
The base class must be a template with one parameter being the derived class:
template <typename D>
class Base {
...
};
and then: class Derived: public Base<Derived> {
...
};
This is called the https://en.wikipedia.org/wiki/Curiously_recurring_template_p...
If that's all you want just write:
When the derived class doesn't have any method "foo_impl" (or no "foo_impl" with a suitable signature), you will get a compile-time error.No need for the static_assert, that was just because KKKKkkkk1 asked whether checking for the existence of a method at compile-time was possible.
Compile-time polymorphism is essentially duck typing: If it quacks like a duck you can treat it as one. If it doesn't quack like a duck, but you still treat it as one you get a compiler error.