Limitations
Limitations(); } }
Additionally, there is another technique called the CRTP idiom in C++ that allows to express polymorphism in compile-time which results at near-zero performance hit during run-time. You derive the base class from the derived class by forwarding the derived class to the base. The base class can be casted to the correct type, that includes the implementation detials, via
static_cast as this is information visible by the compiler. However, this means that the entire interface of the class must be declared in the base class.
Pseudo-virtual call using CRTP (Curiously Recurring Template Pattern)
#include <iostream> template <class Derived> struct Base { void pseudo_virtual() { static_cast<Derived&>(*this).pseudo_virtual(); } }; struct ChildA : public Base<ChildA> { void pseudo_virtual() { std::cout << "A calling." << std::endl; } }; struct ChildB : public Base<ChildB> { void pseudo_virtual() { std::cout << "B calling." << std::endl; } }; template<class Derived> void call_pv(Base<Derived>& base) { base.pseudo_virtual(); }
It is also important to note that CRTP removes the need of using pointer types. If you wish to learn more about CRTP and its uses in SYCL kernels, have a look at our blog post on Enabling Polymorphism in SYCL using CRTP..