dimanche 1 janvier 2017

Map enum value to a type in C++

Is there any way to map enum values to types in C++, including C++11. I have the following enum type:

enum ATTRIBUTE{AGE=0, MENOPAUSE, TUMOR_SIZE, INV_NODES, NODE_CAPS,
               DEG_MALIG, BREAST, BREAST_QUAD, IRRADIAT, CLASS};

I want to map each value of this enum to a certain type. I want to map AGE to int, MENOPAUSE to another enum type, BREAST to bool and so on. So is it possible to create a function which returns a value of type which depends on the value of the attr variable?

//Like that:
auto value = map_attr(ATTRIBUTE attr);
//Here the type of the value variable should be int if the attr variable is AGE, bool for BREAST and so on.

Aucun commentaire:

Enregistrer un commentaire