Well I’m designign publish/subsribe pattern (it’s not observer pattern! many people confuse this). My problem is:
I have enum with topics:
enum topics {gui, combat, physics};
Then for every topic I need 2 containers. Currently I do it maually:
std::vector <cSubscriber *> guiSubscribers;
std::vector <cEvent> guiEvents;
What I want to do is to have a container of vector which uses enum as key. I mean that I can access it in the following way:
events[gui] //it gives me access to vector of gui events
subscribers[combat] //this gives me access to vector of combat subscribers
The key in [] has to be a value from the enum. Is there any way of doing this or I need to do it manually for every topic?
One possibility is a
std::map<topics, std::vector<cEvent>>. However, this is potentially overkill, given that you only have 3 enum values, which will be numbered 0, 1, and 2…