To have any types in template one may just write template <typename ...> struct S {};
.
To have any values (e.g. int
values) in template one may write template <auto ...> struct S {};
.
To have template of any types in template one writes template <template <typename ...> class Tmpl> struct S {};
.
But how to have template of Anythings in template? Anythings meaning 1) types or 2) values or 3) other templates of Anythings? I.e. mix everything what is possible inside template.
I.e. how to write template <template <Anything ...> class Tmpl> struct S {};
types/values/templates can be mixed in any order inside Tmpl
parameters list.
One use case for having such structure S
that accepts any kind of template is to implement template traits, i.e. so that S
can tell somehow 1) how many parameters Tmpl has. 2) for each of parameter (by index) it can tell if it is type or value or another template.
Another use case for S
is that it is needed to implement rich compile time information. I.e. if I can tell all the information about passed-in template, how many and what params it has, then I can compose composite Type Id or Type Name recursively and thus have compile time type reflection.
Also I'm interested in knowing how to intermix at least types and values inside one template in arbitrary order? I.e. how to have template <TypeOrValue ... Args> struct S {};
? Here TypeOrValue
signifies either typename
or auto
in any order or count.
Aucun commentaire:
Enregistrer un commentaire