consider the following templated datastructures
enum eContent{
EINT = 1,
EFLOAT = 2,
EBOOL = 4
};
template<int>
struct Container{
Container(){assert(false);} //woops, don't do that!
};
template<>
struct Container<EINT>{
Container():i(123){}
int i;
};
template<>
struct Container<EFLOAT>{
Container():f(123.456f){}
float f;
};
template<>
struct Container<EBOOL>{
Container():b(true){}
bool b;
};
<fancy macro goes here that creates me all kind of combinations including for example>
template<>
struct Container<EFLOAT | EBOOL>: public Container<EFLOAT>, public Container<EBOOL>{
Container():Container<EFLOAT>(),Container<EBOOL>(){}
};
</fancy macro>
such that I then can for example define a variable like this:
Container<EINT|EFLOAT|EBOOL> myVar;
how would I define this fancy macro?
Why I want this?
Let it be for the sake of fun and learning metaprogramming
But I don’t think it’s good for anything, really, it’s just a solution to the literal problem you stated.
If you have some real problem in mind (for which you think this could be a solution), try to ask about that.
Unless it’s just play, or homework, of course. 🙂
Cheers & hth.,
PS: As a matter of good C++ programming practice, reserve ALL UPPERCASE names for macros, and only for macros. That way you avoid many potential name collisions. Using ALL UPPERCASE for constants is a Java/Python/etc. convention, to some degree suitable for those languages, but decidedly not for C++. It stems from early C, where constants had to be expressed as macros. ALL UPPERCASE was (and is) used for macros, not for constants — well, except Brian Kernighan, but let’s not delve into history… 😉