PR 44436 Associative containers emplace/emplace_hint

Paolo Carlini paolo.carlini@oracle.com
Mon Sep 17 10:12:00 GMT 2012


Hi,

On 09/16/2012 10:08 PM, François Dumont wrote:
> On 09/14/2012 10:43 PM, Paolo Carlini wrote:
>> On 09/14/2012 10:07 PM, François Dumont wrote:
>>> Hi
>>>
>>>     Here is a patch to add emplace/emplace_hint on associative 
>>> containers in C++11 mode.
>> Ah, excellent! I will review the patch over the next couple of days.
>>>     I did some refactoring to use as much of the same code between 
>>> insert and emplace methods..
>>>
>>>     I have also change map::operator[] to now use the emplace logic 
>>> in C++11 so that we only need the value type to be default 
>>> constructible.
>> About this, can I ask you to likewise add completely similar 
>> testcases too?
>
> Good catch Paolo. In fact I simply forgot to add it to the patch.
>
> 2012-09-16  François Dumont  <fdumont@gcc.gnu.org>
>
>     PR libstdc++/44436
>     * include/bits/stl_tree.h
>     (_Rb_tree<>::_M_insert_): Take _Base_ptr rather than
>     _Const_Base_ptr.
>     (_Rb_tree<>::_M_insert_node): New.
>     (_Rb_tree<>::_M_get_insert_unique_pos): New, search code of
>     _M_insert_unique method.
>     (_Rb_tree<>::_M_insert_unique): Use latter.
>     (_Rb_tree<>::_M_emplace_unique): New, likewise.
>     (_Rb_tree<>::_M_get_insert_equal_pos): New, search code of
>     _M_insert_equal method.
>     (_Rb_tree<>::_M_insert_equal): Use latter.
>     (_Rb_tree<>::_M_emplace_equal): New, likewise.
>     (_Rb_tree<>::_M_get_insert_hint_unique_pos): New, search code of
>     _M_insert_unique_ method.
>     (_Rb_tree<>::_M_insert_unique_): Use latter.
>     (_Rb_tree<>::_M_emplace_hint_unique): New, likewise.
>     (_Rb_tree<>::_M_get_insert_hint_equal_pos): New, search code of
>     _M_insert_equal_ method.
>     (_Rb_tree<>::_M_insert_equal_): Use latter.
>     (_Rb_tree<>::_M_emplace_hint_equal): New, likewise.
>     (_Rb_tree<>::_M_insert_lower): Remove first _Base_ptr parameter,
>     useless as always null.
>     * include/bits/stl_map.h: Include <tuple> in C++11.
>     (map<>::operator[](const key_type&)): Use
>     _Rb_tree<>::_M_emplace_hint_unique in C++11.
>     (map<>::operator[](key_type&&)): Likewise.
>     (map<>::emplace): New.
>     (map<>::emplace_hint): New.
>     * include/bits/stl_multimap.h (multimap<>::emplace): New.
>     (multimap<>::emplace_hint): New.
>     * include/bits/stl_set.h (set<>::emplace): New.
>     (set<>::emplace_hint): New.
>     * include/bits/stl_multiset.h (multiset<>::emplace): New.
>     (multiset<>::emplace_hint): New.
>     * include/debug/map.h (std::__debug::map<>::emplace): New.
>     (std::__debug::map<>::emplace_hint): New.
>     * include/debug/multimap.h (std::__debug::multimap<>::emplace):
>     New.
>     (std::__debug::multimap<>::emplace_hint): New.
>     * include/debug/set.h (std::__debug::set<>::emplace): New.
>     (std::__debug::set<>::emplace_hint): New.
>     * include/debug/multiset.h (std::__debug::multiset<>::emplace):
>     New.
>     (std::__debug::multiset<>::emplace_hint): New.
>     * testsuite/util/testsuite_container_traits.h: Signal that emplace
>     and emplace_hint are available on std::map, std::multimap,
>     std::set and std::multiset in C++11.
>     * testsuite/23_containers/map/modifiers/emplate/1.cc: New.
>     * testsuite/23_containers/map/operators/2.cc: New.
>     * testsuite/23_containers/multimap/modifiers/emplate/1.cc: New.
>     * testsuite/23_containers/set/modifiers/emplate/1.cc: New.
>     * testsuite/23_containers/multiset/modifiers/emplate/1.cc: New.
Typo: emplate.
> Ok to commit ?
I say let's just wait another couple of days for more comments and then 
let's go ahead. Patch looks fine to me (thanks again!) and we want the 
code to be available if we want to catch subtler issue in time for the 
release of 4.8.0. Personally, I'm mostly a bit nervous about the various 
const-ness changes, but we should be Ok in terms of testing, because in 
C++11 the various insert and emplace take const_iterators. I'm thinking: 
remember to run the performance testsuite, it should provide quite a bit 
of additional testing of the old insert calls.

Oh well, if you are willing to mechanically add the new functions to the 
profile-mode code too, it would be great. Otherwise I can certainly do it.

Thanks,
Paolo.



More information about the Libstdc++ mailing list