[{"id":35283,"web_url":"https://patchwork.libcamera.org/comment/35283/","msgid":"<175446208326.7787.8996405683915083191@localhost>","date":"2025-08-06T06:34:43","subject":"Re: [PATCH v4 1/2] libcamera: utils: Add scope_exit class","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"content":"Hi Laurent,\n\nThank you for the patch.\n\n\nQuoting Laurent Pinchart (2025-08-05 01:31:50)\n> The scope_exit class is an implementation of the identically named C++\n> library fundamentals TS v3 class, as documented in [1]. It is a simpler\n> version of the libcamera-specific ScopeExitActions class and doesn't\n> require dynamic heap memory allocation, making it more suitable for hot\n> paths.\n> \n> The class is not documented as it implements a C++ standard (even if\n> experimental) API.\n\nHah I was just going to ask for docs - neat trick :-)\n\n> \n> [1] https://en.cppreference.com/w/cpp/experimental/scope_exit/scope_exit.html\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\nThis is useful.\nReviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\nCheers,\nStefan\n\n> ---\n> Changes since v3:\n> \n> - Use LIBCAMERA_DISABLE_COPY_AND_MOVE()\n> \n> Changes since v2:\n> \n> - Drop lvalue reference constraint in constructor\n> - Delete move constructor\n> ---\n>  include/libcamera/base/utils.h | 38 ++++++++++++++++++++++++++++++++++\n>  1 file changed, 38 insertions(+)\n> \n> diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h\n> index 8d5c35782ee3..f21c6dc016ec 100644\n> --- a/include/libcamera/base/utils.h\n> +++ b/include/libcamera/base/utils.h\n> @@ -21,6 +21,7 @@\n>  #include <utility>\n>  #include <vector>\n>  \n> +#include <libcamera/base/class.h>\n>  #include <libcamera/base/private.h>\n>  \n>  #ifndef __DOXYGEN__\n> @@ -428,6 +429,43 @@ private:\n>         std::vector<std::function<void()>> actions_;\n>  };\n>  \n> +#ifndef __DOXYGEN__\n> +template<typename EF>\n> +class scope_exit\n> +{\n> +public:\n> +       template<typename Fn,\n> +                std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Fn>>, scope_exit> &&\n> +                                 std::is_constructible_v<EF, Fn>> * = nullptr>\n> +       explicit scope_exit(Fn &&fn)\n> +               : exitFunction_(std::forward<Fn>(fn))\n> +       {\n> +               static_assert(std::is_nothrow_constructible_v<EF, Fn>);\n> +       }\n> +\n> +       ~scope_exit()\n> +       {\n> +               if (active_)\n> +                       exitFunction_();\n> +       }\n> +\n> +       void release()\n> +       {\n> +               active_ = false;\n> +       }\n> +\n> +private:\n> +       LIBCAMERA_DISABLE_COPY_AND_MOVE(scope_exit)\n> +\n> +       EF exitFunction_;\n> +       bool active_ = true;\n> +};\n> +\n> +template<typename EF>\n> +scope_exit(EF) -> scope_exit<EF>;\n> +\n> +#endif /* __DOXYGEN__ */\n> +\n>  } /* namespace utils */\n>  \n>  #ifndef __DOXYGEN__\n> -- \n> Regards,\n> \n> Laurent Pinchart\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 0E193BE086\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  6 Aug 2025 06:34:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2FB7361464;\n\tWed,  6 Aug 2025 08:34:49 +0200 (CEST)","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 149D061464\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  6 Aug 2025 08:34:47 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:cc39:a2ec:4c28:e184])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 83EA317EB; \n\tWed,  6 Aug 2025 08:33:58 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"YWdxcdDS\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1754462038;\n\tbh=2Vn9TJoLVPkpUph8G/2zdhzlDhVOe3ajyr5/Vj48Wmg=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=YWdxcdDSbZm+B1NOGTppPqpgC3ytqYHMREasZSUZj911HfAz6ZhP7dbtIqDgSke8s\n\tc/sHc4F4gtKCoE+1uQTgKbqaJMBaZkdR7HF4eo05FLVj2syJgxulPxS7HJZS0IDHk/\n\ticj8PTljBCJxhka33Y8KNpSVA6v4+IUkFJM57XlU=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250804233152.11538-2-laurent.pinchart@ideasonboard.com>","References":"<20250804233152.11538-1-laurent.pinchart@ideasonboard.com>\n\t<20250804233152.11538-2-laurent.pinchart@ideasonboard.com>","Subject":"Re: [PATCH v4 1/2] libcamera: utils: Add scope_exit class","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 06 Aug 2025 08:34:43 +0200","Message-ID":"<175446208326.7787.8996405683915083191@localhost>","User-Agent":"alot/0.12.dev8+g2c003385c862.d20250602","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]