4 ms·
In C++, std::map's operator[] will either return the element pointed to by the specified key, or if the key is not in the map, will default construct an object
by ohazi 7y ago
In C++, std::map's operator[] will either return the element pointed to by the specified key, or if the key is not in the map, will default construct an object and insert it into that key's slot in the map.
I really want to know who thought this was a good idea, because I've only ever seen this behavior act as a footgun.