On Mon, 28 Nov 2011, John Doe wrote:
Currently I am participating in a project where a large number of objects are inserted into a std::map. Recently someone replaced all calls of map_instance.insert( std::make_pair(key, value) ); with map_instance.insert( MapType::value_type(key, value) ); claiming it would be faster.
A classic. insert takes a pair<const Key,Value> whereas make_pair produces a pair<Key,Value>, so the first thing the compiler has to do is convert one into the other, ie copy. The set of circumstances where a compiler is allowed to elide a copy is extremely restrictive.
With C++11 you could use emplace instead. -- Marc Glisse