I haven't seen a clear answer to this question about enums. Lets say I have an enum:
enum class TileType
{
WALL= 'W',
PASSAGE= 'P',
MONSTER = 'M',
CRYSTAL= 'C',
};
and I want to typecast and make a new enum with a char Lets say the input char is undefined it the enum:
char id = 'A';
Now when I typecast it there is an undefined behaviour:
TileType type = static_cast<TileType>(id);
Thats why I want to check if the id is a valid value for an enum
//check if enum contains id
bool checkID(char id){...}
Now I have a couple ideas to do it but they seem like over kill to me. I also couldn't find a way to iterate over the enum class to make the check easy but I don't think that's possible.
Is there a way to easily check if the enum contains the id so that I can decide if I can typecast or not? Or am I supposed to do like a switch statement and check for every single case?