I have a tool that autogenerates a lot of C++ code. One thing it generates is a lot of enums. For example:
typedef enum InsId
{
kInsH = 0,
kInsM1 = 1,
kInsM2 = 2,
kNumIns = 3
} InsId;
I have some code that has to convert strings to the aforementioned enums: "kInsH" -> InsId::kInsH
. A map can be used for that (as described in many answers):
const std::unordered_map<InsId, std::string> id_map_{{InsId::kInsH, "kInsH"},
{InsId::kInsM1, "kInsM1"},
{InsId::kInsM2, "kInsM2"}};
The question is: Is there a way to generate those strings at the compile time from the enum field names?
Thank you.