to emplace in case I have the key and the value as separate variables before and don't have the std::pair constructed already? Does emplace have any caveats?
Found this : in case object to be inserted already exists : Actually, not that there is only no actual gain, but there may also be performance loss. emplace needs to construct the key first, and since the key may be both non-copyable and non-movable, it needs to construct the key in the allocated node. On the contrary, insert does not need to allocate when the key is already present in the map. But it's a edge case
Aha, makes sense, thanks In my case I insert only if it doesn't exist, so it should be fine
Обсуждают сегодня