[g++] make_pair inlining failure?

Marc Glisse marc.glisse@inria.fr
Tue Nov 29 09:33:00 GMT 2011


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



More information about the Gcc-help mailing list