/************************************ * file enc : ascii * author : wuyanyi09@gmail.com ************************************/ #ifndef CPPCOMMON_MAP_FUNCTS_H #define CPPCOMMON_MAP_FUNCTS_H #include #include #include #include namespace CPPCOMMON { using namespace std; template string setToString(const set& st) { if(st.empty()) { return "{}"; } stringstream ss; ss<<'{'; typename set::const_iterator it = st.begin(); ss<<*it; it++; while(it != st.end()) { ss<<", "<<*it; it++; } ss<<'}'; return ss.str(); } template string mapToString(const map& mp) { if(mp.empty()) { return "{}"; } stringstream ss; ss<<'{'; typename map::const_iterator it = mp.begin(); ss<first<<": "<second; it++; while(it != mp.end()) { ss<<", "<first<<": "<second; it++; } ss<<'}'; return ss.str(); } template string pairToString(const pair& p) { stringstream ss; ss< void printMap(const map& mp) { for(typename map::const_iterator it = mp.begin(); it != mp.end(); it++) { cout<first<<' '<second< vT getMap(const map& mp, const kT & key, const vT & defaultVal) { typename map::const_iterator it; it = mp.find(key); if(mp.end() == it) { return defaultVal; } return it->second; } } #endif