Let's say I have map<int, int> :
std::map<int, int> map; map.emplace(1, 2); map.insert({3, 4});
Will there be a difference between the two calls?
In the first call, two integers will be copied by value to the emplace function, and then again to the constructor std::pair<int, int> . In the second call, two integers will be copied by value to the constructor std::pair<int, int> , and then copied by value to the internal std::pair<int, int> again as members of the first pair.
I understand the benefits of emplace for types like std::string , where they will be copied by value in the second call and completely moved in the first, but is there any use in using emplace in the described situation
c ++ containers c ++ 14
coyotte508
source share