mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: treat self-assignment as no-op instead of a Fatal (#1473)
- this can help if using std algorithms that return a const reference such as std::min() does.
This commit is contained in:
committed by
Andrew Heather
parent
883752cfb9
commit
b0c88dff58
@ -656,6 +656,11 @@ void Foam::HashTable<T, Key, Hash>::clearStorage()
|
||||
template<class T, class Key, class Hash>
|
||||
void Foam::HashTable<T, Key, Hash>::swap(HashTable<T, Key, Hash>& rhs)
|
||||
{
|
||||
if (this == &rhs)
|
||||
{
|
||||
return; // Self-swap is a no-op
|
||||
}
|
||||
|
||||
Foam::Swap(size_, rhs.size_);
|
||||
Foam::Swap(capacity_, rhs.capacity_);
|
||||
Foam::Swap(table_, rhs.table_);
|
||||
@ -665,6 +670,11 @@ void Foam::HashTable<T, Key, Hash>::swap(HashTable<T, Key, Hash>& rhs)
|
||||
template<class T, class Key, class Hash>
|
||||
void Foam::HashTable<T, Key, Hash>::transfer(HashTable<T, Key, Hash>& rhs)
|
||||
{
|
||||
if (this == &rhs)
|
||||
{
|
||||
return; // Self-assignment is a no-op
|
||||
}
|
||||
|
||||
clear();
|
||||
swap(rhs);
|
||||
}
|
||||
@ -759,12 +769,9 @@ void Foam::HashTable<T, Key, Hash>::operator=
|
||||
const HashTable<T, Key, Hash>& rhs
|
||||
)
|
||||
{
|
||||
// Check for assignment to self
|
||||
if (this == &rhs)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "attempted assignment to self"
|
||||
<< abort(FatalError);
|
||||
return; // Self-assignment is a no-op
|
||||
}
|
||||
|
||||
if (!capacity_)
|
||||
@ -813,12 +820,9 @@ void Foam::HashTable<T, Key, Hash>::operator=
|
||||
HashTable<T, Key, Hash>&& rhs
|
||||
)
|
||||
{
|
||||
// Check for assignment to self
|
||||
if (this == &rhs)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "attempted assignment to self"
|
||||
<< abort(FatalError);
|
||||
return; // Self-assignment is a no-op
|
||||
}
|
||||
|
||||
transfer(rhs);
|
||||
|
||||
Reference in New Issue
Block a user