forked from boostorg/container
Fixes #145 ("Allocations not handled correctly in some cases of vector move with unequal allocators")
This commit is contained in:
@@ -59,18 +59,18 @@ public:
|
||||
|
||||
template <typename T> friend class SimpleAllocator;
|
||||
|
||||
friend bool operator == (const SimpleAllocator &, const SimpleAllocator &)
|
||||
{ return true; }
|
||||
friend bool operator == (const SimpleAllocator &a, const SimpleAllocator &b)
|
||||
{ return a.m_state == b.m_state; }
|
||||
|
||||
friend bool operator != (const SimpleAllocator &, const SimpleAllocator &)
|
||||
{ return false; }
|
||||
friend bool operator != (const SimpleAllocator &a, const SimpleAllocator &b)
|
||||
{ return a.m_state != b.m_state; }
|
||||
};
|
||||
|
||||
class alloc_int
|
||||
{
|
||||
private: // Not copyable
|
||||
|
||||
BOOST_MOVABLE_BUT_NOT_COPYABLE(alloc_int)
|
||||
BOOST_COPYABLE_AND_MOVABLE(alloc_int)
|
||||
|
||||
public:
|
||||
typedef SimpleAllocator<int> allocator_type;
|
||||
@@ -87,13 +87,30 @@ class alloc_int
|
||||
other.m_value = -1;
|
||||
}
|
||||
|
||||
alloc_int(const alloc_int &other)
|
||||
: m_value(other.m_value), m_allocator(boost::move(other.m_allocator))
|
||||
{
|
||||
}
|
||||
|
||||
alloc_int(const alloc_int &other, const allocator_type &allocator)
|
||||
: m_value(other.m_value), m_allocator(allocator)
|
||||
{
|
||||
}
|
||||
|
||||
alloc_int(int value, const allocator_type &allocator)
|
||||
: m_value(value), m_allocator(allocator)
|
||||
{}
|
||||
|
||||
alloc_int & operator=(BOOST_RV_REF(alloc_int)other)
|
||||
{
|
||||
other.m_value = other.m_value;
|
||||
m_value = other.m_value;
|
||||
other.m_value = -1;
|
||||
return *this;
|
||||
}
|
||||
|
||||
alloc_int & operator=(const alloc_int &other)
|
||||
{
|
||||
m_value = other.m_value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -368,24 +385,47 @@ bool one_level_allocator_propagation_test()
|
||||
{
|
||||
allocator_type al(SimpleAllocator<value_type>(4));
|
||||
ContainerWrapper c2(al);
|
||||
{
|
||||
iterator it = c2.emplace(c2.cbegin(), 41);
|
||||
if(!test_value_and_state_equals(*it, 41, 4))
|
||||
return false;
|
||||
}
|
||||
|
||||
ContainerWrapper c(::boost::move(c2), allocator_type(SimpleAllocator<value_type>(5)));
|
||||
|
||||
c.clear();
|
||||
iterator it = c.emplace(c.cbegin(), 42);
|
||||
|
||||
if(!test_value_and_state_equals(*it, 42, 5))
|
||||
if(!test_value_and_state_equals(*c.begin(), 41, 5))
|
||||
return false;
|
||||
}/*
|
||||
|
||||
{
|
||||
c.clear();
|
||||
iterator it = c.emplace(c.cbegin(), 42);
|
||||
|
||||
if(!test_value_and_state_equals(*it, 42, 5))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
{
|
||||
ContainerWrapper c2(allocator_type(SimpleAllocator<value_type>(3)));
|
||||
allocator_type al(SimpleAllocator<value_type>(4));
|
||||
ContainerWrapper c2(al);
|
||||
{
|
||||
iterator it = c2.emplace(c2.cbegin(), 41);
|
||||
if(!test_value_and_state_equals(*it, 41, 4))
|
||||
return false;
|
||||
}
|
||||
|
||||
ContainerWrapper c(c2, allocator_type(SimpleAllocator<value_type>(5)));
|
||||
|
||||
c.clear();
|
||||
iterator it = c.emplace(c.cbegin(), 42);
|
||||
|
||||
if(!test_value_and_state_equals(*it, 42, 5))
|
||||
if(!test_value_and_state_equals(*c.begin(), 41, 5))
|
||||
return false;
|
||||
}*/
|
||||
|
||||
{
|
||||
c.clear();
|
||||
iterator it = c.emplace(c.cbegin(), 42);
|
||||
|
||||
if(!test_value_and_state_equals(*it, 42, 5))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user