This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [g++] make_pair inlining failure?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]