mirror of
https://github.com/boostorg/algorithm.git
synced 2025-07-06 09:16:33 +02:00
self assignment problem in is_any_ofF fixed
[SVN r48281]
This commit is contained in:
@ -141,9 +141,12 @@ namespace boost {
|
|||||||
// Assignment
|
// Assignment
|
||||||
is_any_ofF& operator=(const is_any_ofF& Other)
|
is_any_ofF& operator=(const is_any_ofF& Other)
|
||||||
{
|
{
|
||||||
|
// Handle self assignment
|
||||||
|
if(this==&Other) return *this;
|
||||||
|
|
||||||
// Prepare storage
|
// Prepare storage
|
||||||
const set_value_type* SrcStorage=0;
|
const set_value_type* SrcStorage;
|
||||||
set_value_type* DestStorage=0;
|
set_value_type* DestStorage;
|
||||||
|
|
||||||
if(use_fixed_storage(Other.m_Size))
|
if(use_fixed_storage(Other.m_Size))
|
||||||
{
|
{
|
||||||
@ -162,23 +165,44 @@ namespace boost {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Use dynamic storage
|
// Other uses dynamic storage
|
||||||
|
|
||||||
// Create new buffer
|
|
||||||
set_value_type* pTemp=new set_value_type[Other.m_Size];
|
|
||||||
DestStorage=pTemp;
|
|
||||||
SrcStorage=Other.m_Storage.m_dynSet;
|
SrcStorage=Other.m_Storage.m_dynSet;
|
||||||
|
|
||||||
// Delete old storage if necessary
|
|
||||||
if(!use_fixed_storage(m_Size) && m_Storage.m_dynSet!=0)
|
|
||||||
{
|
|
||||||
delete [] m_Storage.m_dynSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store the new storage
|
// Check what kind of storage are we using right now
|
||||||
m_Storage.m_dynSet=pTemp;
|
if(use_fixed_storage(m_Size))
|
||||||
// Set new size
|
{
|
||||||
m_Size=Other.m_Size;
|
// Using fixed storage, allocate new
|
||||||
|
set_value_type* pTemp=new set_value_type[Other.m_Size];
|
||||||
|
DestStorage=pTemp;
|
||||||
|
m_Storage.m_dynSet=pTemp;
|
||||||
|
m_Size=Other.m_Size;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Using dynamic storage, check if can reuse
|
||||||
|
if(m_Storage.m_dynSet!=0 && m_Size>=Other.m_Size && m_Size<Other.m_Size*2)
|
||||||
|
{
|
||||||
|
// Reuse the current storage
|
||||||
|
DestStorage=m_Storage.m_dynSet;
|
||||||
|
m_Size=Other.m_Size;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Allocate the new one
|
||||||
|
set_value_type* pTemp=new set_value_type[Other.m_Size];
|
||||||
|
DestStorage=pTemp;
|
||||||
|
|
||||||
|
// Delete old storage if necessary
|
||||||
|
if(m_Storage.m_dynSet!=0)
|
||||||
|
{
|
||||||
|
delete [] m_Storage.m_dynSet;
|
||||||
|
}
|
||||||
|
// Store the new storage
|
||||||
|
m_Storage.m_dynSet=pTemp;
|
||||||
|
// Set new size
|
||||||
|
m_Size=Other.m_Size;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the data
|
// Copy the data
|
||||||
|
@ -102,6 +102,7 @@ void test_pred(const Pred& pred, const Input& input, bool bYes)
|
|||||||
// test assignment operator
|
// test assignment operator
|
||||||
Pred pred1=pred;
|
Pred pred1=pred;
|
||||||
pred1=pred;
|
pred1=pred;
|
||||||
|
pred1=pred1;
|
||||||
if(bYes)
|
if(bYes)
|
||||||
{
|
{
|
||||||
BOOST_CHECK( all( input, pred ) );
|
BOOST_CHECK( all( input, pred ) );
|
||||||
|
Reference in New Issue
Block a user