In the code below, Foo<T>::setValue works well for my purposes, except in cases where where T is a class enum named TYPE e.g. Bar::TYPE and Baz:TYPE.
Therefore, I’d appreciate help specializing Foo<T>::setValue without naming Bar and Baz, because there could be dozens of such classes.
class Bar
{
public:
enum TYPE{ ONE , TWO };
};
class Baz
{
public:
enum TYPE{ SIX , TEN };
};
template<typename T>
class Foo
{
public:
void setValue(){} // Need a different setValue if T is a class enum
private:
T m_value;
};
int main()
{
Foo<int> f1;
Foo<Bar::TYPE> f2;
Foo<Baz::TYPE> f3;
return EXIT_SUCCESS;
}
You can do this with something like:
Where
enable_ifpicks which version to use based on theis_enumtype trait.The example used C++11
enable_ifandis_enumbut boost has similar for pre-C++11 also.