Fix move_if_noexcept usages in _Hashtable
François Dumont
frs.dumont@gmail.com
Tue Dec 4 06:45:00 GMT 2018
Hi
 This patch fix a minor problem with usage of std::move_if_noexcept.
We use it to move node content if move construtor is noexcept but we
eventually use the allocator_type::construct method which might be
slightly different. I think it is better to check for this method
noexcept qualification.
 Moreover I have added a special overload for nodes containing a
std::pair. It is supposed to allow move semantic in associative
containers where Key is stored as const deleting std::pair move
constructor. In this case we should still move the Value part.
 It doesn't work for the moment because the std::pair piecewise
constructor has no noexcept qualification. Is there any plan to add it ?
I think adding it will force including <tuple> in stl_pair.h, is it fine ?
 If this evolution is accepted I'll adapt it for _Rb_tree that has the
same problem.
 Working on this I also notice that content of initialization_list is
not moved. Is there a plan to make initialization_list iterator type
like move_iterator ? Should containers use
__make_move_iterator_if_noexcept ?
 Tested under Linux x86_64 normal mode.
 Ok to commit this first step ?
   * include/bits/stl_construct.h (__construct_object_a): New.
   (struct _Construct_object_a): New, use latter.
   (__move_construct_object_a): New.
   (struct _Move_construct_object_a): New, use latter.
   (struct _Move_construct_if_noexcept_a): New.
   * include/std/tuple (__move_construct_object_a): New overload for
   std::pair.
   * include/ext/throw_allocator.h
   (throw_allocator_base<>::construct<_Up, _Args...>): Add noexcept
   qualification.
   * testsuite/util/testsuite_allocator.h
   (tracker_allocator<>::construct<_Up, _Args...>): Likewise.
   * include/bits/hashtable_policy.h: Include <bits/stl_construct.h>
   (_Hashtable_alloc<>::_M_allocate_node_f): New.
   (_Hashtable_alloc<>::_M_allocate_node): Adapt, use latter.
   (_AllocNode<>::operator()<_Args...>): Likewise.
   (_AllocNode<_NodeAlloc, _ConstructF>): Inherit from _ConstructF.
   (_AllocNode<>::_M_construct_f()): New.
   (_ReuseOrAllocNode<>): Inherits from _AllocNode.
   * include/bits/hashtable.h:
   (_Hashtable<>::__alloc_node_gen_t): New template alias to _NodeAlloc.
   (_Hashtable<>::__reuse_or_alloc_node_type): Replace with...
   (_Hashtable<>::__reuse_or_alloc_node_gen_t): ...that.
   (_Hashtable<>::_M_assign_elements<>): Remove _NodeGenerator parameter.
   (_Hashtable<>::operator=(initializer_list<>)): Adapt.
   (_Hashtable<>::operator=(const _Hashtable&)): Adapt.
   (_Hashtable<>::_M_move_assign(_Hashtable&&, false_type)): Adapt.
   (_Hashtable<>::_Hashtable(const _Hashtable&)): Adapt.
   (_Hashtable<>::_Hashtable(const _Hashtable&, const allocator_type&)):
   Adapt.
   (_Hashtable<>::_Hashtable(_Hashtable&&, const allocator_type&)): Adapt.
   * testsuite/23_containers/unordered_map/allocator/move_assign.cc:
   (test01): Add checks.
   (test02): Likewise.
   * testsuite/23_containers/unordered_set/allocator/move_assign.cc:
   (test04): New.
François
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hashtable.patch
Type: text/x-patch
Size: 19023 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20181204/df833d2e/attachment.bin>
More information about the Libstdc++
mailing list