Is it possible to write a class:
template<typename T, ... name> struct Magic {
T name;
};
such that:
Magic<int, foo> gives:
Magic<int, foo> {
int foo;
}
and
Magic<float, bar> gives:
Magic<float, bar> {
float bar;
}
Basically, I want to be able to specify not only the Type, but also the name of the member variables.
That is not possible, you have to resort to either macro-based solutions or use a predefined set of types that provide named members.
A possible macro-based approach:
or:
Using preprocessor magic, e.g. utilizing Boost.Preprocessor, you should be able to generate n named members in a more convenient way.
Another approach might be using a predefined set of classes providing certain named members from that you inherit:
Using compile-time lists you could then inherit from n
named_memberinstantiations, Boost.MPL could help here.