In C ++ 17, you can use std::variant<int, std::string> , before that you can use one of boost :
using IntOrString = std::variant<int, std::string>; std::map<std::string, IntOrString> myMap; myMap["first_key"] = 10; myMap["second_key"] = "stringValue";
source share