Boost logo

Boost :

Subject: Re: [boost] [ptr_container] associative container insert takes reference instead of const reference as key ?
From: Thorsten Ottosen (tottosen_at_[hidden])
Date: 2018-08-29 08:25:10


Den 27-08-2018 kl. 15:03 skrev comic fans via Boost:
> Hello , I've found that ptr_unordered_map.insert has following
> signature (from code and latest doc)
>
> std::pair<iterator,bool> insert( key_type& k, T* x );
>
> that forbids calls like ptr_unordered_map.insert( myobj->id(), myobj)
> ,I wonder if this is by design , or some other reason ? why other
> overload takes const key_type& k as key type? and insert always call
> insert_impl which have const reference as key type ? any help would
> be appreciated.

It is by design.

https://www.boost.org/doc/libs/1_67_0/libs/ptr_container/doc/faq.html#why-does-ptr-map-t-insert-replace-take-two-arguments-the-key-and-the-pointer-instead-of-one-std-pair-and-why-is-the-key-passed-by-non-const-reference

regards

-Thorsten


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk