lundi 13 mars 2023

C++ Variadic Template: Construct a list of class members

I would like to create class members through a variadic template so that a template defined like this:

template<typename firstType, firstName, Rest... rest>
class MyClass{
FirstType firstName;
//do something recursvy: https://stackoverflow.com/questions/7230621/how-can-i-iterate-over-a-packed-variadic-template-argument-list
};

with the following instance:

class MyClass<int A, float B, char c>

would generate a class like this:

class MyClass{
int A;
float B;
charc;
}

How do I do this?

I can only picture doing this with nasty C macros.





Aucun commentaire:

Enregistrer un commentaire