#include "iostream"
using namespace std;
enum EnumValue
{
One = 100,
Two,
Three
};
template<class EnumType>
struct EnumValueUnit
{
int indexValue;
EnumType enumValue;
};
#define InvalidateValue ((int)-1)
template<typename EnumType>
EnumType MatchToEnum(int index, const EnumValueUnit<EnumType> *enumMap)
{
size_t i = 0;
for (; enumMap[i].indexValue != InvalidateValue; ++i)
{
if (index == enumMap[i].indexValue)
break;
}
return enumMap[i].enumValue;
}
void main()
{
static EnumValueUnit<EnumValue> testMap[] =
{
1, One,
2, Two,
3, Three,
InvalidateValue, One,
};
EnumValue value = MatchToEnum(2, testMap);
cout << value << endl;
}
using namespace std;
enum EnumValue
{
One = 100,
Two,
Three
};
template<class EnumType>
struct EnumValueUnit
{
int indexValue;
EnumType enumValue;
};
#define InvalidateValue ((int)-1)
template<typename EnumType>
EnumType MatchToEnum(int index, const EnumValueUnit<EnumType> *enumMap)
{
size_t i = 0;
for (; enumMap[i].indexValue != InvalidateValue; ++i)
{
if (index == enumMap[i].indexValue)
break;
}
return enumMap[i].enumValue;
}
void main()
{
static EnumValueUnit<EnumValue> testMap[] =
{
1, One,
2, Two,
3, Three,
InvalidateValue, One,
};
EnumValue value = MatchToEnum(2, testMap);
cout << value << endl;
}