Suppose I have some kind of type list
template<typename... Types> struct TypeList {};
Now in some other class I can generate such a TypeList
in a variety of ways.
template<class T> struct MyClass {
using MyList = TypeList<T, typename Something<T>::type, SomethingElse>;
// ...
};
How can I declare a method with types of arguments extracted from this type list? For example, if I set MyList = TypeList<int, float, const char*>
, I wish a method
void my_method(int, float, const char*)
to be declared.
You could derive from a base class that implements the method:
template <typename> struct MethodProvider;
template <typename ...Args>
struct MethodProvider<TypeList<Args...>>
{
void my_method(Args ...args);
};
template <typename T>
struct MyClassAux
{
using MyList = TypeList<T, typename Something<T>::type, SomethingElse>;
};
template <typename T>
struct MyClass
: private MyClassAux<T>
, private MethodProvider<typename MyClassAux<T>::MyList>
{
using typename MyClassAux<T>::MyList;
using MethodProvider<typename MyClassAux<T>::MyList>::my_method;
// ...
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With