tmp: Added move assignment operator
This provides the same behaviour as the assign operator, but with certain checks removed as they do not apply when the source tmp is an rvalue and will therefore not be retained after the assignment operation. It is also consistent with and complimentary to the behaviour of the move constructor.
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -167,6 +167,9 @@ public:
|
||||
|
||||
//- Assignment transferring the temporary T to this tmp
|
||||
inline void operator=(const tmp<T>&);
|
||||
|
||||
//- Move assignment transferring the temporary T to this tmp
|
||||
inline void operator=(const tmp<T>&&);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -369,8 +369,6 @@ inline void Foam::tmp<T>::operator=(const tmp<T>& t)
|
||||
|
||||
if (t.isAnyTmp())
|
||||
{
|
||||
type_ = t.type_;
|
||||
|
||||
// if (!t.ptr_)
|
||||
// {
|
||||
// FatalErrorInFunction
|
||||
@ -378,7 +376,9 @@ inline void Foam::tmp<T>::operator=(const tmp<T>& t)
|
||||
// << abort(FatalError);
|
||||
// }
|
||||
|
||||
type_ = t.type_;
|
||||
ptr_ = t.ptr_;
|
||||
|
||||
t.ptr_ = 0;
|
||||
}
|
||||
else
|
||||
@ -391,4 +391,19 @@ inline void Foam::tmp<T>::operator=(const tmp<T>& t)
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::tmp<T>::operator=(const tmp<T>&& t)
|
||||
{
|
||||
clear();
|
||||
|
||||
type_ = t.type_;
|
||||
ptr_ = t.ptr_;
|
||||
|
||||
if (isAnyTmp())
|
||||
{
|
||||
t.ptr_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
Reference in New Issue
Block a user