forked from boostorg/container
Fixed #9916: "Allocator propagation incorrect in the assignment operator of most".
Fixed #9932: "Missing assignment operator from related static_vector". Added missing details from issue #9915
This commit is contained in:
1 parent
bffd6c036c
commit
0b720f82b4
16 files changed
+372
-283
No files matched your search
@@ -743,35 +743,42 @@ class stable_vector
|
||||
//! <b>Postcondition</b>: x.empty(). *this contains a the elements x had
|
||||
//! before the function.
|
||||
//!
|
||||
//! <b>Throws</b>: If allocator_type's copy constructor throws.
|
||||
//! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
|
||||
//! is false and (allocation throws or T's move constructor throws)
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear.
|
||||
//! <b>Complexity</b>: Constant if allocator_traits_type::
|
||||
//! propagate_on_container_move_assignment is true or
|
||||
//! this->get>allocator() == x.get_allocator(). Linear otherwise.
|
||||
stable_vector& operator=(BOOST_RV_REF(stable_vector) x)
|
||||
BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment)
|
||||
{
|
||||
if (&x != this){
|
||||
node_allocator_type &this_alloc = this->priv_node_alloc();
|
||||
node_allocator_type &x_alloc = x.priv_node_alloc();
|
||||
//If allocators are equal we can just swap pointers
|
||||
if(this_alloc == x_alloc){
|
||||
//Destroy objects but retain memory
|
||||
this->clear();
|
||||
this->index = boost::move(x.index);
|
||||
this->priv_swap_members(x);
|
||||
//Move allocator if needed
|
||||
container_detail::bool_<allocator_traits_type::
|
||||
propagate_on_container_move_assignment::value> flag;
|
||||
container_detail::move_alloc(this->priv_node_alloc(), x.priv_node_alloc(), flag);
|
||||
}
|
||||
//If unequal allocators, then do a one by one move
|
||||
else{
|
||||
this->assign( boost::make_move_iterator(x.begin())
|
||||
, boost::make_move_iterator(x.end()));
|
||||
}
|
||||
//for move constructor, no aliasing (&x != this) is assummed.
|
||||
BOOST_ASSERT(this != &x);
|
||||
node_allocator_type &this_alloc = this->priv_node_alloc();
|
||||
node_allocator_type &x_alloc = x.priv_node_alloc();
|
||||
const bool propagate_alloc = allocator_traits_type::
|
||||
propagate_on_container_move_assignment::value;
|
||||
container_detail::bool_<propagate_alloc> flag;
|
||||
const bool allocators_equal = this_alloc == x_alloc; (void)allocators_equal;
|
||||
//Resources can be transferred if both allocators are
|
||||
//going to be equal after this function (either propagated or already equal)
|
||||
if(propagate_alloc || allocators_equal){
|
||||
//Destroy objects but retain memory in case x reuses it in the future
|
||||
this->clear();
|
||||
//Move allocator if needed
|
||||
container_detail::move_alloc(this_alloc, x_alloc, flag);
|
||||
//Take resources
|
||||
this->index = boost::move(x.index);
|
||||
this->priv_swap_members(x);
|
||||
}
|
||||
//Else do a one by one move
|
||||
else{
|
||||
this->assign( boost::make_move_iterator(x.begin())
|
||||
, boost::make_move_iterator(x.end()));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//! <b>Effects</b>: Assigns the n copies of val to *this.
|
||||
//!
|
||||
//! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
|
||||
|
||||
Reference in new issue
Block a user