Shorten the path to a C ++ enum element (using typedef or typename) to use as a template parameter
I have a rather complex object,
MyNamespace::MyClass::MySubStruct
which has
enum
{
ONE = 1,
TWO = 2
};
Now I have another class that has a template parameter
template <unsigned int x> class Foo;
I am currently initializing B like this
Foo<MyNamespace::MyClass::MySubStruct::ONE> MyFoo
and it works great, but it is too much, especially considering that I am initializing this class about a hundred times.
I would like to write something like:
typedef MyNamespace::MyClass::MySubStruct::ONE MyONE
Foo<MyOne> MyFoo
Naturally this doesn't compile, nor does it declare it as const unsigned int inside the class. How do you do this elegantly?
+3
source to share
2 answers