Value type of map need not be default copyable

Marc Glisse marc.glisse@inria.fr
Wed Aug 8 07:35:00 GMT 2012


On Tue, 7 Aug 2012, Richard Smith wrote:

>> I've attached a patch for unordered_map which solves the rvalue
>> reference problem.  For efficiency, I've created a new
>> _M_emplace_bucket method rather than call emplace directly.
>> 
>> I've verified all libstdc++ tests pass (sorry for the previous
>> oversight) and am running the full GCC test suite now.  However, I'd
>> appreciate any feedback on whether this is a reasonable approach.  STL
>> hacking is way outside my comfort zone.  ;-)
>> 
>> If this looks good, I'll take a stab at std::map.
> 
> I think you should remove the mapped_type() argument from the call to
> _M_emplace_bucket. In C++11, the mapped_type is not required to be copyable
> at all, just to be DefaultInsertable.

Indeed. The reason I was talking about emplace is that you want an object 
to be created only at the time the node is created. That might mean 
passing piecewise_construct_t and an empty tuple to emplace (otherwise it 
is too similar to insert). Or for unordered_map where the node functions 
are "exposed", you could just create the node directly without passing 
through emplace.

-- 
Marc Glisse



More information about the Libstdc++ mailing list