[v3 PATCH] Implement N4279, Improved insertion interface for unique-key maps.
Jonathan Wakely
jwakely@redhat.com
Fri Aug 7 08:36:00 GMT 2015
On 21/07/15 00:49 +0300, Ville Voutilainen wrote:
>Tested on Linux-PPC64.
>
>2015-07-21 Ville Voutilainen <ville.voutilainen@gmail.com>
> Implement N4279, Improved insertion interface for unique-key maps.
> * include/bits/stl_map.h (try_emplace, insert_or_assign): New.
> * include/bits/stl_tree.h (_M_get_insert_unique_pos,
> _M_get_insert_equal_pos, _M_get_insert_hint_unique_pos,
> _M_get_insert_hint_equal_pos): Make public.
> * include/bits/unordered_map.h (try_emplace, insert_or_assign): New.
> * testsuite/23_containers/map/modifiers/insert_or_assign/1.cc:
> Likewise.
> * testsuite/23_containers/map/modifiers/try_emplace/1.cc: Likewise.
> * testsuite/23_containers/unordered_map/modifiers/insert_or_assign.cc:
> Likewise.
> * testsuite/23_containers/unordered_map/modifiers/try_emplace.cc:
> Likewise.
+ template <typename... _Args>
+ pair<iterator, bool>
Indent everything after 'template<...>' please.
+ try_emplace(const key_type& __k, _Args&&... __args)
+ {
+ iterator __i = lower_bound(__k);
+ if (__i == end() || key_comp()(__k, (*__i).first))
+ {
+ __i = emplace_hint(__i, std::piecewise_construct,
+ std::forward_as_tuple(__k),
+ std::forward_as_tuple(std::forward<_Args>(__args)...));
+ return {__i, true};
+ }
+ return {__i, false};
+ }
Add a blank line between functions please.
+ // move-capable overload
+ template <typename... _Args>
+ pair<iterator, bool>
+ try_emplace(key_type&& __k, _Args&&... __args)
+ template <typename _M>
_M isn't documented as a BADNAME but single character names like that make me
nervous, would _Obj or _Up be OK?
+ pair<iterator, bool>
+ insert_or_assign(const key_type& __k, _M&& __obj)
+ {
More information about the Libstdc++
mailing list