If you know in advance that all types of values mapwill be held, use boost::variant. Or use boost::any. With the help of, boost::anyyou can subsequently add entries with any type of value to the map.
Sample code with boost::variant:
Map creation:
typedef boost::variant<std::string, std::map<int, int>, int> MyVariantType;
std::map<std::string, MyVariantType> hash;
Adding entries:
hash["somedata"] = "Hello, yo, me being a simple string";
std::map<int, int> temp;
temp[6] = 5;
temp[13] = 9;
hash["somearray"] = temp;
hash["simple_data_again"] = 198792;
Getting Values:
std::string s = boost::get<std::string>(hash["somedata"]);
int i = boost::get<int>(hash["simple_data_again"]);
@Matthieu M , boost::variant. , boost::variant operator<, .
boost::any:
:
std::map<std::string, boost::any> hash;
:
hash["somedata"] = "Hello, yo, me being a simple string";
std::map<int, int> temp;
temp[6] = 5;
temp[13] = 9;
hash["somearray"] = temp;
hash["simple_data_again"] = 198792;
:
std::string s = boost::any_cast<std::string>(hash["somedata"]);
int i = boost::any_cast<int>(hash["simple_data_again"]);
, boost::any (). - , , .
:
++ - . , , , , ++. - .
++. ++ .
: