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:
Will Bainbridge
2021-02-11 15:12:16 +00:00
parent 94e5094f04
commit 6c1adf6fc2
2 changed files with 21 additions and 3 deletions

View File

@ -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>&&);
};

View File

@ -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;
}
}
// ************************************************************************* //