insert vs emplace vs operator[] in c++ map

I’m using maps for the first time and I realized that there are many ways to insert an element. You can use emplace(), operator[] or insert(), plus variants like using value_type or make_pair. While there is a lot of information about all of them and questions about particular cases, I still can’t understand the big picture.
So, my two questions are:

  1. What is the advantage of each one of them over the others?

  2. Was there any need for adding emplace to the standard? Is there anything that wasn’t possible before without it?

6 Answers
6

Leave a Comment