[ptr_container] associative container insert takes reference instead of const reference as key ?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[ptr_container] associative container insert takes reference instead of const reference as key ?

Boost - Dev mailing list
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.

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [ptr_container] associative container insert takes reference instead of const reference as key ?

Boost - Dev mailing list
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

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [ptr_container] associative container insert takes reference instead of const reference as key ?

Boost - Dev mailing list
Thank you for the explanation, I missed the FAQ part
On Wed, Aug 29, 2018 at 4:25 PM Thorsten Ottosen via Boost
<[hidden email]> wrote:

>
> 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
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [ptr_container] associative container insert takes reference instead of const reference as key ?

Boost - Dev mailing list
In reply to this post by Boost - Dev mailing list
Thanks for the explanation, but if Key is POD type, we still can not
using const reference ?

regards

-
On Wed, Aug 29, 2018 at 4:25 PM Thorsten Ottosen via Boost
<[hidden email]> wrote:

>
> 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
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [ptr_container] associative container insert takes reference instead of const reference as key ?

Boost - Dev mailing list
Den 29-08-2018 kl. 12:10 skrev comic fans:
> Thanks for the explanation, but if Key is POD type, we still can not
> using const reference ?
yeah, I guess one could put an overload via enable_if if the
copy-constructor was noexcept.

-T

--
Best regards,
Thorsten Jørgen Ottosen, Ph.D.
Director of Research
+45 23308797
Dezide (www.dezide.com)


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [ptr_container] associative container insert takes reference instead of const reference as key ?

Boost - Dev mailing list
ok, I may take a try

regards
On Wed, Aug 29, 2018 at 6:52 PM Thorsten Ottosen <[hidden email]> wrote:

>
> Den 29-08-2018 kl. 12:10 skrev comic fans:
> > Thanks for the explanation, but if Key is POD type, we still can not
> > using const reference ?
> yeah, I guess one could put an overload via enable_if if the
> copy-constructor was noexcept.
>
> -T
>
> --
> Best regards,
> Thorsten Jørgen Ottosen, Ph.D.
> Director of Research
> +45 23308797
> Dezide (www.dezide.com)
>

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost