aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-11-01 12:49:53 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2024-11-13 20:21:39 +0000
commitafc9351ebbac1ed55d7c472af817b172bdb662e6 (patch)
tree6797dd7a24eb84b8da3a9b351313b9803bd83b36 /libcpp
parent9fcbbb3d104717447cffb65f6ef000969a7b7bb4 (diff)
downloadgcc-afc9351ebbac1ed55d7c472af817b172bdb662e6.zip
gcc-afc9351ebbac1ed55d7c472af817b172bdb662e6.tar.gz
gcc-afc9351ebbac1ed55d7c472af817b172bdb662e6.tar.bz2
libstdc++: Allow unordered_set assignment to assign to existing nodes
Currently the _ReuseOrAllocNode::operator(Args&&...) function always destroys the value stored in recycled nodes and constructs a new value. The _ReuseOrAllocNode type is only ever used for implementing assignment, either from another unordered container of the same type, or from std::initializer_list<value_type>. Consequently, the parameter pack Args only ever consists of a single parameter or type const value_type& or value_type. We can replace the variadic parameter pack with a single forwarding reference parameter, and when the value_type is assignable from that type we can use assignment instead of destroying the existing value and then constructing a new one. Using assignment is typically only possible for sets, because for maps the value_type is std::pair<const key_type, mapped_type> and in most cases std::is_assignable_v<const key_type&, const key_type&> is false. libstdc++-v3/ChangeLog: * include/bits/hashtable_policy.h (_ReuseOrAllocNode::operator()): Replace parameter pack with a single parameter. Assign to existing value when possible. * testsuite/23_containers/unordered_multiset/allocator/move_assign.cc: Adjust expected count of operations. * testsuite/23_containers/unordered_set/allocator/move_assign.cc: Likewise. Reviewed-by: François Dumont <fdumont@gcc.gnu.org>
Diffstat (limited to 'libcpp')
0 files changed, 0 insertions, 0 deletions