Add moved_value_from() to container policies, enabling proper move semantics for node-based containers in the case of unequal allocators

This commit is contained in:
Christian Mazakas
2023-01-11 14:37:45 -08:00
parent a3d4a078de
commit 7ce7ef5050
5 changed files with 29 additions and 2 deletions

View File

@ -1255,7 +1255,7 @@ public:
* elements' values.
*/
x.for_all_elements([this](element_type* p){
unchecked_insert(type_policy::move(*p));
unchecked_insert(type_policy::moved_value_from(*p));
});
}
}
@ -1352,7 +1352,7 @@ public:
* elements' values.
*/
x.for_all_elements([this](element_type* p){
unchecked_insert(type_policy::move(*p));
unchecked_insert(type_policy::moved_value_from(*p));
});
}
}

View File

@ -60,6 +60,11 @@ namespace boost {
std::move(const_cast<raw_mapped_type&>(x.second))};
}
static moved_type moved_value_from(element_type& x)
{
return move(x);
}
template <class A>
static void construct(A& al, element_type* p, moved_type&& x)
{

View File

@ -45,6 +45,11 @@ namespace boost {
static element_type&& move(element_type& x) { return std::move(x); }
static element_type&& moved_value_from(element_type& x)
{
return move(x);
}
template <class A>
static void construct(A& al, element_type* p, element_type const& copy)
{

View File

@ -46,12 +46,24 @@ namespace boost {
{
value_type* p;
/*
* we use a defined copy constructor here so the type is no longer
* trivially copy-constructible which inhibits our memcpy
* optimizations when copying the tables
*/
element_type() : p(nullptr) {}
element_type(element_type const& rhs) : p(rhs.p) {}
};
static value_type& value_from(element_type x) { return *(x.p); }
static std::pair<raw_key_type&&, raw_mapped_type&&> moved_value_from(
element_type& x)
{
return {std::move(const_cast<raw_key_type&>(x.p->first)),
std::move(const_cast<raw_mapped_type&>(x.p->second))};
}
template <class K, class V>
static raw_key_type const& extract(std::pair<K, V> const& kv)
{

View File

@ -57,6 +57,11 @@ namespace boost {
static Key const& extract(element_type k) { return *k.p; }
static element_type&& move(element_type& x) { return std::move(x); }
static value_type&& moved_value_from(element_type& x)
{
return std::move(*x.p);
}
template <class A>
static void construct(A& al, element_type* p, element_type const& copy)
{