I have 5 classes that are used as operators :
TurnOn , TurnOff , PushBox , Exit , Enter
And I have for each type , a string that holds a description of that type .
For instance :
class Places {
enum Type { Room1 ,Room2 ,Room3 ,Room4 };
// more stuff
};
TurnOn turnOn(Places::Room1);
string turnOnString = "TurnOn(Room1)" ;
I want to store the info in a map , so I have 5 maps for each operator :
map <string , TurnOn > opeatorTurnOn;
map <string , TurnOff > opeatorTurnOff ;
map <string , PushBox > opeatorTPushBox ;
map <string , Exit > opeatorExit ;
map <string , Enter > opeatorEnter ;
But now I have 5 maps with the same concept : a string with its operator .
How can I store the operators in one map so I won’t have to hold 5 maps with the same concept ?
It depends on how your operator classes are implemented (we have very little information), but I’d make a map of callables, something similar to this:
You could also always wrap the ops in lambdas if you don’t use the
operator()overloading.