From 6c1adf6fc2575d84d4514b4c3e131df28f9765c9 Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Thu, 11 Feb 2021 15:12:16 +0000 Subject: [PATCH] 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. --- src/OpenFOAM/memory/tmp/tmp.H | 5 ++++- src/OpenFOAM/memory/tmp/tmpI.H | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/OpenFOAM/memory/tmp/tmp.H b/src/OpenFOAM/memory/tmp/tmp.H index 4b2708ea1d..7854634e72 100644 --- a/src/OpenFOAM/memory/tmp/tmp.H +++ b/src/OpenFOAM/memory/tmp/tmp.H @@ -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&); + + //- Move assignment transferring the temporary T to this tmp + inline void operator=(const tmp&&); }; diff --git a/src/OpenFOAM/memory/tmp/tmpI.H b/src/OpenFOAM/memory/tmp/tmpI.H index 2a2cd32597..e63e1c56c6 100644 --- a/src/OpenFOAM/memory/tmp/tmpI.H +++ b/src/OpenFOAM/memory/tmp/tmpI.H @@ -369,8 +369,6 @@ inline void Foam::tmp::operator=(const tmp& t) if (t.isAnyTmp()) { - type_ = t.type_; - // if (!t.ptr_) // { // FatalErrorInFunction @@ -378,7 +376,9 @@ inline void Foam::tmp::operator=(const tmp& t) // << abort(FatalError); // } + type_ = t.type_; ptr_ = t.ptr_; + t.ptr_ = 0; } else @@ -391,4 +391,19 @@ inline void Foam::tmp::operator=(const tmp& t) } +template +inline void Foam::tmp::operator=(const tmp&& t) +{ + clear(); + + type_ = t.type_; + ptr_ = t.ptr_; + + if (isAnyTmp()) + { + t.ptr_ = 0; + } +} + + // ************************************************************************* //