Let’s say I have a std::map<int, std::map<int, std::string>>, is there a way to lookup directly for a string if you are given the two keys in a shorter statement?
Some syntax sugar for:
std::map<int, std::map<int, std::string>> nested_map;
nested_map[1][3] = "toto";
int key1 = 1;
int key2 = 3;
std::string val;
auto it1 = nested_map.find(key1);
if (it1 != nested_map.end())
{
auto it2 = it1->second.find(key2);
if (it2 != it1->second.end())
{
val = it2->second;
}
}
Edit: I am only looking for syntax sugar to save typing a bit, because there are a lot of these nested maps in my code.
Edit2: I don’t want to throw on failure.