[{"id":3398,"web_url":"https://patchwork.libcamera.org/comment/3398/","msgid":"<20200110230457.GB4859@pendragon.ideasonboard.com>","date":"2020-01-10T23:04:57","subject":"Re: [libcamera-devel] [PATCH v3 03/33] libcamera: utils: Add\n\texchange()","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 Fri, Jan 10, 2020 at 08:37:38PM +0100, Niklas Söderlund wrote:\n> C++11 does not support std::exchange(), add a custom implementation in\n> utils.\n\nThis is now only used by the FrameBuffer move constructor, which I think\nshould be dropped (I'll comment on that in the corresponding patch), so\nthis patch could possibly be dropped too.\n\n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/libcamera/include/utils.h | 9 +++++++++\n>  src/libcamera/utils.cpp       | 8 ++++++++\n>  2 files changed, 17 insertions(+)\n> \n> diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h\n> index badc77533fa15f09..6470cadc2c6c1234 100644\n> --- a/src/libcamera/include/utils.h\n> +++ b/src/libcamera/include/utils.h\n> @@ -67,6 +67,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 5de9e4813353b23c..a7e573ac45aec914 100644\n> --- a/src/libcamera/utils.cpp\n> +++ b/src/libcamera/utils.cpp\n> @@ -95,6 +95,14 @@ 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> + * \\brief Replace the value of \\a obj with \\a new_value and return the old value\n> + * \\param[inout] obj Object whose value to replace\n> + * \\param[in] new_value The value to assign to obj\n> + * \\return The old value of \\a obj\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 F25696067C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 11 Jan 2020 00:05:11 +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 4D03D52F;\n\tSat, 11 Jan 2020 00:05:11 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1578697511;\n\tbh=dpg4GGo9GwFF33QYrCejZkxX/JQs+BtfV+v3fmersoo=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=lseC4JR8HkLvgi/aM0eWjlZtNORU9h4IjXNxEAo+k/DTZPiQpwDpr70yeMF0bwhBR\n\t0byyAZBNzAnSLMwmQhShMHkB3ls+y1O1oAn4fAAcLDoUyc1Xa1SGtWuhTRy+MUoLuD\n\taxdti8WOE4AvSNbnzQYh8kdER2EHGpqqBpkfHfzA=","Date":"Sat, 11 Jan 2020 01:04:57 +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":"<20200110230457.GB4859@pendragon.ideasonboard.com>","References":"<20200110193808.2266294-1-niklas.soderlund@ragnatech.se>\n\t<20200110193808.2266294-4-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":"<20200110193808.2266294-4-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v3 03/33] libcamera: utils: Add\n\texchange()","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":"Fri, 10 Jan 2020 23:05:12 -0000"}}]