[{"id":3265,"web_url":"https://patchwork.libcamera.org/comment/3265/","msgid":"<20191216121821.GB4856@pendragon.ideasonboard.com>","date":"2019-12-16T12:18:21","subject":"Re: [libcamera-devel] [PATCH 1/3] libcamera: utils: Add exchange()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nThank you for the patch.\n\nOn Mon, Dec 16, 2019 at 01:10:27PM +0100, Niklas Söderlund wrote:\n> C++11 does not support std::exchange(), add a custom implementation in\n> utils.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/libcamera/include/utils.h | 9 +++++++++\n>  src/libcamera/utils.cpp       | 7 +++++++\n>  2 files changed, 16 insertions(+)\n> \n> diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h\n> index a80f7d096bf725a1..32e3b009040d9efc 100644\n> --- a/src/libcamera/include/utils.h\n> +++ b/src/libcamera/include/utils.h\n> @@ -66,6 +66,15 @@ const T& clamp(const T& v, const T& lo, const T& hi)\n>  \treturn std::max(lo, std::min(v, hi));\n>  }\n>  \n> +/* C++11 doesn't provide std::exchange */\n> +template<class T, class U = T>\n> +T exchange(T &obj, U &&new_value)\n> +{\n> +\tT old_value = std::move(obj);\n> +\tobj = std::forward<U>(new_value);\n> +\treturn old_value;\n> +}\n> +\n>  using clock = std::chrono::steady_clock;\n>  using duration = std::chrono::steady_clock::duration;\n>  using time_point = std::chrono::steady_clock::time_point;\n> diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\n> index d632f6e66638038d..0e2decd966dd8d0c 100644\n> --- a/src/libcamera/utils.cpp\n> +++ b/src/libcamera/utils.cpp\n> @@ -95,6 +95,13 @@ char *secure_getenv(const char *name)\n>   * \\return lo if v is less than lo, hi if v is greater than hi, otherwise v\n>   */\n>  \n> +/**\n> + * \\fn libcamera::utils::exchange(T &obj, U &&new_value)\n\nIt would b e nice to also explain what the function does ;-)\n\n * \\brief Replace the value of \\a obj with \\a new_value and return the old value\n\n> + * \\param[in] obj object whose value to replace\n\nIsn't this a param[inout] ?\n\ns/object/Object/\n\n> + * \\param[in] new_value the value to assign to obj\n\ns/the/The/\n\n> + * \\return The old value of obj\n\ns/obj/\\\\a obj/\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> + */\n> +\n>  /**\n>   * \\typedef clock\n>   * \\brief The libcamera clock (monotonic)","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E908F601E4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Dec 2019 13:18:30 +0100 (CET)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 50820A34;\n\tMon, 16 Dec 2019 13:18:30 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1576498710;\n\tbh=zsy0SqXp5v00e/KXH2NvKB6ZPLdC6yEOdmHRFr78o4Y=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=qMpLOq+5aToXGgzD9OBLF6XV/FMXEhUexVuAMVRdE+/GaQX66zkFJDT7mzEjmoO+r\n\t08XLTCpTxN9LKencKoBldw16HLjvVRQLFIzUWpUZkeLa41KVqKKnS4rfmr97S7lpy/\n\tGJNqVAQagfjxIrcQek2jN9oyjLcJijj1aR+XKybY=","Date":"Mon, 16 Dec 2019 14:18:21 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191216121821.GB4856@pendragon.ideasonboard.com>","References":"<20191216121029.1048242-1-niklas.soderlund@ragnatech.se>\n\t<20191216121029.1048242-2-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20191216121029.1048242-2-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [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":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Mon, 16 Dec 2019 12:18:31 -0000"}}]