I have the following structure:
std::map<int, std::map<int, int>> my_map; I want to check whether the key my_map[3][5] exists.
Is there any easier/shorter way to do so except for something like:
if (my_map.find(3) != my_map.end()) { std::map<int, int>& internal_map = my_map[3]; if (internal_map.find(5) != internal_map.end()) { // ... Do something ... } }
count()instead offind.count()means count of a specific key? But this is a map - the count can be only 0 or 1, am I wrong? Don't new values with same key override the former ones?countdoes exactly that. Yes, it can only be 0 or 1 for amaporset. It's the same complexity asfind, may or may not be a tad faster (it doesn't have to construct an iterator).