I want to have a map that uses
like this:
std::map<std::string, SOME TYPE> myMap;
myMap["first_key"] = 10;
myMap["second_key"] = "stringValue";
What is the SIMPLEST way to do such thing?
added) I am looking for solution that works in c++11
In c++17, you may use std::variant<int, std::string>
, prior to this, you may use the one from boost
:
using IntOrString = std::variant<int, std::string>;
std::map<std::string, IntOrString> myMap;
myMap["first_key"] = 10;
myMap["second_key"] = "stringValue";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With