Using The [] Operator Efficiently With C++ unordered_map
operator[] will insert an entry for you with a default-constructed value, if one isn’t already there. It is equivalent to, but will probably be implemented more efficiently than: iterator iter = map.find(key); if(iter == map.end()) { iter = map.insert(value_type(key, int())).first; } return *iter; operator[] can be quicker than doing the work manually with find() and … Read more