samedi 28 août 2021

enable templated base class only for derived classes

How would I go about doing the equivalent of the following?

template < class T, typename = std::enable_if< std::is_base_of< Self, T >::value > > // Can not use std::is_base_of on self
class Self {
protected:
    typedef T self;
};

class ValidDerived : public Self< ValidDerived > { }; // This should compile because T is itself

class InvalidDerived : public Self< ValidDerived > { }; // This should not compile because T is not itself

I'm trying to implement reflection and to do that one of the steps I have to make is getting the typeid( self ).name() of the most-derived class.





Aucun commentaire:

Enregistrer un commentaire