I have a producer class that stores consumers object pointers in a array of std::set under different categories in order to notify the consumers of different state data changing.
std::set consumers<Consumer*>[NUM_STATE_CATEGORIES];
Because the notify logic is pretty much the same across all the different types of state data, I’d like to make a generic function to notify of the state changes, but call a different consumer function depending on the state change.
for(auto it = consumers[category1].begin(); it != consumers[category1].end(); it++)
{
(*it)->NotifyCategory1Changed(this);
}
for(auto it = consumers[category2].begin(); it != consumers[category2].end(); it++)
{
(*it)->NotifyCategory2Changed(this);
}
Is there a way to send a function pointer to a generic that will help me point to each of the consumer objects or will I need to create a container to store each function pointer?
for(auto it = consumers[category].begin(); it != consumers[category].end(); it++)
{
(*it)->GENERIC_FUNCTION_AS_PARAMETER(this);
}
Can GENERIC_FUNCTION_AS_PARAMETER be sent to point to all the saved off Consumer pointer functions of that category?