The following question relates to a programming technique Andrei Alexandrescu presents in Modern C++ Design. Due to the lack of time, I assume you either have read it or understand the concept via experience.
In his book, Alexandrescu shows a generic programming technique he calls "Mapping Integral Constant to Types" in chapter 2, section 2.4. Here is an example.
Code:
template <int A>
struct Int2Type
{
enum {type = A};
};
enum TypeA{WIN = 0x0000, LOSS};
template <typename T, int U>
class XYZ
{
T *Create(Int2Type<WIN>);
T *Create(Int2Type<LOSS>);
};
// Usage
XYZ<MyClass, WIN> zyx;
Again, I assume you understand the concept above.
XYZ<MyClass, WIN> ... compiles as along as you pass in WIN or LOSS. However, here is what I want to do, but have not been able to get Visual C++ to compile without errors.
Code:
TypeA myType;
myType = WIN;
XYZ<MyClass, myType> zyx;
I would like to know if there is a solution to the problem above.
The general idea is I want to pass in WIN or LOSS via a variable. The reason I have not implemented WIN and/or LOSS instead of the variable is because in the way I have setup the algorithm. Typing in WIN and LOSS will require switch states and if/else statements.
Thanks,
Kuphryn