3 ms·
I use this all the time in C++. std::map<std::string, boost::function<void (int)>> handlerMap; boost::assign::insert(handlerMap) ("football", &handleFo
by pushingbits 17y ago
I use this all the time in C++.
std::map<std::string, boost::function<void (int)>> handlerMap;
boost::assign::insert(handlerMap)
("football", &handleFootball)
("comedy", &handleComedy)
("crime", &handleCrime);
handlerMap["football"](channelNumber);
Makes the code so much easier to understand. And when the handler functions start getting too complex, you can just add another level:
handlerMap["comedy"]["situational_comedy"](channelNumber);