jeudi 11 juillet 2019

Generate one method per type from variadic class template

I would like to have a variadic class template to generate one method per type, such that for example a class template like the following:

template <class T, class ... Ts>
class MyClass {
public:
    virtual void hello(const T& t) = 0;
};

would make available the methods hello(const double&) and hello(const int&) when instantiated as MyClass<double, int> myclass;`

Note that I want the class to be pure abstract, such that a derived class would actually need to do the implementation, e.g.:

class Derived : MyClass<double, int> {
public:
    inline void hello(const double& t) override { }
    inline void hello(const int& t) override { }
};

This problem is somewhat similar to this one, but I couldn't understand how to adapt it to my case.

Aucun commentaire:

Enregistrer un commentaire