mirror of
https://github.com/boostorg/unordered.git
synced 2025-07-30 11:27:15 +02:00
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:
@ -1255,7 +1255,7 @@ public:
|
|||||||
* elements' values.
|
* elements' values.
|
||||||
*/
|
*/
|
||||||
x.for_all_elements([this](element_type* p){
|
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.
|
* elements' values.
|
||||||
*/
|
*/
|
||||||
x.for_all_elements([this](element_type* p){
|
x.for_all_elements([this](element_type* p){
|
||||||
unchecked_insert(type_policy::move(*p));
|
unchecked_insert(type_policy::moved_value_from(*p));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,11 @@ namespace boost {
|
|||||||
std::move(const_cast<raw_mapped_type&>(x.second))};
|
std::move(const_cast<raw_mapped_type&>(x.second))};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static moved_type moved_value_from(element_type& x)
|
||||||
|
{
|
||||||
|
return move(x);
|
||||||
|
}
|
||||||
|
|
||||||
template <class A>
|
template <class A>
|
||||||
static void construct(A& al, element_type* p, moved_type&& x)
|
static void construct(A& al, element_type* p, moved_type&& x)
|
||||||
{
|
{
|
||||||
|
@ -45,6 +45,11 @@ namespace boost {
|
|||||||
|
|
||||||
static element_type&& move(element_type& x) { return std::move(x); }
|
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>
|
template <class A>
|
||||||
static void construct(A& al, element_type* p, element_type const& copy)
|
static void construct(A& al, element_type* p, element_type const& copy)
|
||||||
{
|
{
|
||||||
|
@ -46,12 +46,24 @@ namespace boost {
|
|||||||
{
|
{
|
||||||
value_type* p;
|
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() : p(nullptr) {}
|
||||||
element_type(element_type const& rhs) : p(rhs.p) {}
|
element_type(element_type const& rhs) : p(rhs.p) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
static value_type& value_from(element_type x) { return *(x.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>
|
template <class K, class V>
|
||||||
static raw_key_type const& extract(std::pair<K, V> const& kv)
|
static raw_key_type const& extract(std::pair<K, V> const& kv)
|
||||||
{
|
{
|
||||||
|
@ -57,6 +57,11 @@ namespace boost {
|
|||||||
static Key const& extract(element_type k) { return *k.p; }
|
static Key const& extract(element_type k) { return *k.p; }
|
||||||
static element_type&& move(element_type& x) { return std::move(x); }
|
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>
|
template <class A>
|
||||||
static void construct(A& al, element_type* p, element_type const& copy)
|
static void construct(A& al, element_type* p, element_type const& copy)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user