Today I just notice empty_map[key] will create an null element in the map. I was not expecting that. Is there a map like container where i’ll just get null and not create an element? I suppose there isn’t and need to replace all my [] with .find()
Share
You’re stuck with find(). That’s just how
mapis designed, and there’s no similar container with that behaviour as the only difference. (Or as BoBTFish said, you can useat)To elaborate a bit more, you can’t have a reference to a NULL value. This means you can you either have an iterator that points to the element or end(), or you can have a method that either returns a reference or throws an exception.
find()andat()are those two options.