From patchwork Mon Dec 16 12:10:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 2425 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CA622601E7 for ; Mon, 16 Dec 2019 13:10:57 +0100 (CET) X-Halon-ID: 167af101-1ffd-11ea-8e92-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p54ac5865.dip0.t-ipconnect.de [84.172.88.101]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 167af101-1ffd-11ea-8e92-005056917f90; Mon, 16 Dec 2019 13:10:51 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Mon, 16 Dec 2019 13:10:27 +0100 Message-Id: <20191216121029.1048242-2-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191216121029.1048242-1-niklas.soderlund@ragnatech.se> References: <20191216121029.1048242-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/3] libcamera: utils: Add exchange() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Dec 2019 12:10:58 -0000 C++11 does not support std::exchange(), add a custom implementation in utils. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/libcamera/include/utils.h | 9 +++++++++ src/libcamera/utils.cpp | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h index a80f7d096bf725a1..32e3b009040d9efc 100644 --- a/src/libcamera/include/utils.h +++ b/src/libcamera/include/utils.h @@ -66,6 +66,15 @@ const T& clamp(const T& v, const T& lo, const T& hi) return std::max(lo, std::min(v, hi)); } +/* C++11 doesn't provide std::exchange */ +template +T exchange(T &obj, U &&new_value) +{ + T old_value = std::move(obj); + obj = std::forward(new_value); + return old_value; +} + using clock = std::chrono::steady_clock; using duration = std::chrono::steady_clock::duration; using time_point = std::chrono::steady_clock::time_point; diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp index d632f6e66638038d..0e2decd966dd8d0c 100644 --- a/src/libcamera/utils.cpp +++ b/src/libcamera/utils.cpp @@ -95,6 +95,13 @@ char *secure_getenv(const char *name) * \return lo if v is less than lo, hi if v is greater than hi, otherwise v */ +/** + * \fn libcamera::utils::exchange(T &obj, U &&new_value) + * \param[in] obj object whose value to replace + * \param[in] new_value the value to assign to obj + * \return The old value of obj + */ + /** * \typedef clock * \brief The libcamera clock (monotonic)