This adds a convenient _M_assign overload for the common case where the
node generator is the _AllocNode type. Only two places need to call
_M_assign with a _ReuseOrAllocNode node generator, so all the other
calls to _M_assign can use the new overload instead of manually
constructing a node generator.
The _AllocNode::operator(Args&&...) function doesn't need to be a
variadic template. It is only ever called with a single argument of type
const value_type& or value_type&&, so could be simplified. That isn't
done in this commit.
libstdc++-v3/ChangeLog:
* include/bits/hashtable.h (_Hashtable): Remove typedefs for
node generators.
(_Hashtable::_M_assign(_Ht&&)): Add new overload.
(_Hashtable::operator=(initializer_list<value_type>)): Add local
typedef for node generator.
(_Hashtable::_M_assign_elements): Likewise.
(_Hashtable::operator=(const _Hashtable&)): Use new _M_assign
overload.
(_Hashtable(const _Hashtable&)): Likewise.
(_Hashtable(const _Hashtable&, const allocator_type&)):
Likewise.
(_Hashtable(_Hashtable&&, __node_alloc_type&&, false_type)):
Likewise.
* include/bits/hashtable_policy.h (_Insert): Remove typedef for
node generator.
Reviewed-by: François Dumont <[email protected]>
---
Most of this patch series *removes* overloaded names, making overload
resolution simpler. This one adds an overload of _M_assign where there
was previously only one function template with that name. I think the
increased usability for the common case is worth it.
libstdc++-v3/include/bits/hashtable.h | 34 +++++++++++---------
libstdc++-v3/include/bits/hashtable_policy.h | 1 -
2 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/libstdc++-v3/include/bits/hashtable.h
b/libstdc++-v3/include/bits/hashtable.h
index 23484f711cc..bf6eed7c1c6 100644
--- a/libstdc++-v3/include/bits/hashtable.h
+++ b/libstdc++-v3/include/bits/hashtable.h
@@ -299,12 +299,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Equal, _Hash, _RangeHash, _Unused,
_RehashPolicy, _Traits>;
- using __reuse_or_alloc_node_gen_t =
- __detail::_ReuseOrAllocNode<__node_alloc_type>;
- using __alloc_node_gen_t =
- __detail::_AllocNode<__node_alloc_type>;
- using __node_builder_t =
- __detail::_NodeBuilder<_ExtractKey>;
+ using __node_builder_t = __detail::_NodeBuilder<_ExtractKey>;
// Simple RAII type for managing a node containing an element
struct _Scoped_node
@@ -480,6 +475,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
void
_M_assign_elements(_Ht&&);
+ template<typename _Ht>
+ void
+ _M_assign(_Ht&& __ht)
+ {
+ __detail::_AllocNode<__node_alloc_type> __alloc_node_gen(*this);
+ _M_assign(std::forward<_Ht>(__ht), __alloc_node_gen);
+ }
+
template<typename _Ht, typename _NodeGenerator>
void
_M_assign(_Ht&&, _NodeGenerator&);
@@ -608,6 +611,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Hashtable&
operator=(initializer_list<value_type> __l)
{
+ using __reuse_or_alloc_node_gen_t =
+ __detail::_ReuseOrAllocNode<__node_alloc_type>;
+
__reuse_or_alloc_node_gen_t __roan(_M_begin(), *this);
_M_before_begin._M_nxt = nullptr;
clear();
@@ -1308,10 +1314,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_bucket_count = __ht._M_bucket_count;
_M_element_count = __ht._M_element_count;
_M_rehash_policy = __ht._M_rehash_policy;
- __alloc_node_gen_t __alloc_node_gen(*this);
__try
{
- _M_assign(__ht, __alloc_node_gen);
+ _M_assign(__ht);
}
__catch(...)
{
@@ -1340,6 +1345,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::
_M_assign_elements(_Ht&& __ht)
{
+ using __reuse_or_alloc_node_gen_t =
+ __detail::_ReuseOrAllocNode<__node_alloc_type>;
+
__buckets_ptr __former_buckets = nullptr;
std::size_t __former_bucket_count = _M_bucket_count;
__rehash_guard_t __rehash_guard(_M_rehash_policy);
@@ -1517,8 +1525,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_element_count(__ht._M_element_count),
_M_rehash_policy(__ht._M_rehash_policy)
{
- __alloc_node_gen_t __alloc_node_gen(*this);
- _M_assign(__ht, __alloc_node_gen);
+ _M_assign(__ht);
}
template<typename _Key, typename _Value, typename _Alloc,
@@ -1572,8 +1579,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_element_count(__ht._M_element_count),
_M_rehash_policy(__ht._M_rehash_policy)
{
- __alloc_node_gen_t __alloc_node_gen(*this);
- _M_assign(__ht, __alloc_node_gen);
+ _M_assign(__ht);
}
template<typename _Key, typename _Value, typename _Alloc,
@@ -1612,12 +1618,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
else
{
- __alloc_node_gen_t __alloc_gen(*this);
-
using _Fwd_Ht = __conditional_t<
__move_if_noexcept_cond<value_type>::value,
const _Hashtable&, _Hashtable&&>;
- _M_assign(std::forward<_Fwd_Ht>(__ht), __alloc_gen);
+ _M_assign(std::forward<_Fwd_Ht>(__ht));
__ht.clear();
}
}
diff --git a/libstdc++-v3/include/bits/hashtable_policy.h
b/libstdc++-v3/include/bits/hashtable_policy.h
index caedb0258ef..cf97e571c1e 100644
--- a/libstdc++-v3/include/bits/hashtable_policy.h
+++ b/libstdc++-v3/include/bits/hashtable_policy.h
@@ -978,7 +978,6 @@ namespace __detail
using __unique_keys = typename _Traits::__unique_keys;
using __node_alloc_type = typename __hashtable_alloc::__node_alloc_type;
- using __node_gen_type = _AllocNode<__node_alloc_type>;
[[__gnu__::__always_inline__]]
__hashtable&
--
2.47.0