/////////////////////////////////////////////////////////////////////// // MT4Q3.cpp - std::unordered_map // // // // Jim Fawcett, CSE687 - Object Oriented Design Midterm, Spring 2018 // /////////////////////////////////////////////////////////////////////// #include #include #include #include #include "../StringUtilities/StringUtilities.h" template std::string showTypeName(const Container& container) { std::string cName = typeid(container).name(); // ugh! too long size_t pos = cName.find_first_of('<'); cName = cName.substr(0, pos); std::string kType = typeid(Key).name(); pos = kType.find_first_of('<'); kType = kType.substr(0, pos); std::string vType = typeid(Value).name(); pos = vType.find_first_of('<'); vType = vType.substr(0, pos); std::ostringstream out; out << cName << "<" << kType << ", " << vType << ">"; return out.str(); } template void show(const Container& container) { std::string typeName = showTypeName(container); std::cout << "\n " << typeName; std::cout << "\n " << std::string(typeName.size() + 2, '-'); for (auto item : container) { std::cout << "\n { " << item.first << ", " << item.second << " }"; } } int main() { Utilities::Title("MT4Q3 - std::unordered_map"); Utilities::putline(); std::unordered_map demoMap; demoMap["Pei"] = 23; demoMap["Amberkar"] = 22; using Key = std::string; using Value = double; show(demoMap); Utilities::putline(); demoMap["zhang"] = 23; show(demoMap); Utilities::putline(); demoMap["zhang"] = 555; show(demoMap); std::cout << "\n\n"; return 0; }