Skip to content

Instantly share code, notes, and snippets.

@bbhavsar
Last active December 28, 2015 11:08
Show Gist options
  • Save bbhavsar/7490750 to your computer and use it in GitHub Desktop.
Save bbhavsar/7490750 to your computer and use it in GitHub Desktop.
typedef int (*ProcessParamFuncPtr)(void);
typedef std::map< std::string, ProcessParamFuncPtr> ProcessFuncMap;
// Initialize map with appropriate functions for the datatype.
ProcessFuncMap map = boost::assign::map_list_of
("int64", process_param< UConfigParamInt, int >)
("bool", process_param< UConfigParamBool, bool >)
("float", process_param< UConfigParamFloat, float >)
("string", process_param< UConfigParamString, std::string>);
// Invoke function based on the datatype
std::string type = get_type();
ProcessFuncMap::iterator it = map.find(type);
if (it != map.end()) {
ProcessParamFuncPtr fptr = (*it).second;
int ret = fptr();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment