[{"id":35241,"web_url":"https://patchwork.libcamera.org/comment/35241/","msgid":"<e9441b57-184b-45eb-9624-eae149a80f5f@ideasonboard.com>","date":"2025-07-30T07:58:51","subject":"Re: [PATCH v2 1/2] libcamera: utils: Add scope_exit class","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"Hi\n\n2025. 07. 29. 18:21 keltezéssel, Laurent Pinchart írta:\n> +template<typename EF>\n> +class scope_exit\n> +{\n> +public:\n> +\ttemplate<typename Fn,\n> +\t\t std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Fn>>, scope_exit> &&\n> +\t\t\t\t  std::is_constructible_v<EF, Fn> &&\n> +\t\t\t\t  !std::is_lvalue_reference_v<Fn>> * = nullptr>\n\nI think it should be fine to remove the lvalue condition since we require\nnothrow constructibility.\n\n\n> +\texplicit scope_exit(Fn &&fn)\n> +\t\t: exitFunction_(std::forward<Fn>(fn))\n> +\t{\n> +\t\tstatic_assert(std::is_nothrow_constructible_v<EF, Fn>);\n> +\t}\n> +\n> +\tscope_exit(scope_exit &&other)\n\nI would probably =delete this until a need arises.\n\n\n> +\t\t: exitFunction_(std::move(other.exitFunction_)),\n> +\t\t  active_(other.active_)\n\nI like std::exchange a lot... so I'd write\n\n   std::exchange(other.active_, false)\n\n\nRegards,\nBarnabás Pőcze\n\n> +\t{\n> +\t\tother.release();\n> +\t}\n> +\n> +\tscope_exit(const scope_exit &) = delete;\n> +\n> +\t~scope_exit()\n> +\t{\n> +\t\tif (active_)\n> +\t\t\texitFunction_();\n> +\t}\n> +\n> +\tvoid release()\n> +\t{\n> +\t\tactive_ = false;\n> +\t}\n> +\n> +private:\n> +\tEF exitFunction_;\n> +\tbool active_ = true;\n> +};\n> +\n> +template<typename EF>\n> +scope_exit(EF) -> scope_exit<EF>;\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 8B986BDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 30 Jul 2025 07:59:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9EF54691F1;\n\tWed, 30 Jul 2025 09:59:12 +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 DBD3B6913B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 30 Jul 2025 09:58:55 +0200 (CEST)","from [192.168.33.11] (185.182.214.105.nat.pool.zt.hu\n\t[185.182.214.105])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 04C46833;\n\tWed, 30 Jul 2025 09:58:11 +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=\"pzy0dble\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1753862292;\n\tbh=IJ4m4zxqHCk9fR9VoMIMfJJiKwZmxaL7Rd1jhY/hzMU=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=pzy0dbleoL2m37EkLNrSVUPNW3QJe7PSHHT/8kVpB1H+yAW3qnU4tiGuKtJR/Lt2/\n\t4KyMYekDWuold7ThK7kflYjSF5d+/aGkdg6XSs16thIAEYXAwoiHqoSbgfvmvZu0Sp\n\tijRFE+t5Q9qdnePKuO9YkiIrZ4X9xLA2Pfr9U8LI=","Message-ID":"<e9441b57-184b-45eb-9624-eae149a80f5f@ideasonboard.com>","Date":"Wed, 30 Jul 2025 09:58:51 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2 1/2] libcamera: utils: Add scope_exit class","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Cc":"Han-Lin Chen <hanlinchen@chromium.org>,\n\tHarvey Yang <chenghaoyang@chromium.org>","References":"<20250729162101.13836-1-laurent.pinchart@ideasonboard.com>\n\t<20250729162101.13836-2-laurent.pinchart@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20250729162101.13836-2-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","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>"}},{"id":35243,"web_url":"https://patchwork.libcamera.org/comment/35243/","msgid":"<20250730092309.GB17990@pendragon.ideasonboard.com>","date":"2025-07-30T09:23:09","subject":"Re: [PATCH v2 1/2] libcamera: utils: Add scope_exit class","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Wed, Jul 30, 2025 at 09:58:51AM +0200, Barnabás Pőcze wrote:\n> 2025. 07. 29. 18:21 keltezéssel, Laurent Pinchart írta:\n> > +template<typename EF>\n> > +class scope_exit\n> > +{\n> > +public:\n> > +\ttemplate<typename Fn,\n> > +\t\t std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Fn>>, scope_exit> &&\n> > +\t\t\t\t  std::is_constructible_v<EF, Fn> &&\n> > +\t\t\t\t  !std::is_lvalue_reference_v<Fn>> * = nullptr>\n> \n> I think it should be fine to remove the lvalue condition since we require\n> nothrow constructibility.\n\nWill be done in v3.\n\n> > +\texplicit scope_exit(Fn &&fn)\n> > +\t\t: exitFunction_(std::forward<Fn>(fn))\n> > +\t{\n> > +\t\tstatic_assert(std::is_nothrow_constructible_v<EF, Fn>);\n> > +\t}\n> > +\n> > +\tscope_exit(scope_exit &&other)\n> \n> I would probably =delete this until a need arises.\n> \n> \n> > +\t\t: exitFunction_(std::move(other.exitFunction_)),\n> > +\t\t  active_(other.active_)\n> \n> I like std::exchange a lot... so I'd write\n> \n>    std::exchange(other.active_, false)\n\nAgreed, but I'll instead delete the function :-)\n\n> > +\t{\n> > +\t\tother.release();\n> > +\t}\n> > +\n> > +\tscope_exit(const scope_exit &) = delete;\n> > +\n> > +\t~scope_exit()\n> > +\t{\n> > +\t\tif (active_)\n> > +\t\t\texitFunction_();\n> > +\t}\n> > +\n> > +\tvoid release()\n> > +\t{\n> > +\t\tactive_ = false;\n> > +\t}\n> > +\n> > +private:\n> > +\tEF exitFunction_;\n> > +\tbool active_ = true;\n> > +};\n> > +\n> > +template<typename EF>\n> > +scope_exit(EF) -> scope_exit<EF>;\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 394D6BDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 30 Jul 2025 09:23:21 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2E722691F6;\n\tWed, 30 Jul 2025 11:23:20 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B0CEE6913B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 30 Jul 2025 11:23:18 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 1B6402EC;\n\tWed, 30 Jul 2025 11:22:35 +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=\"ezP1WkXg\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1753867355;\n\tbh=8tNIsSJlgj8HUVYsE5P2Vp0ugd8PTP9B0jxiR3ulBUQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ezP1WkXgY5P3X4K+AN2HjApOxTlnmAeIrMs086H4hhJWHCKNni1BmgmO0p5iWge8M\n\tXhhs0eJ5iOv4xCvZBPHvpDjMj10mMtxmq88Wv990NecxJF60Zou8Hol9V+hMKt7eDI\n\tO7RbfOeuWjVZIsCpGET05XtJNid00wQNoSW6ZnN0=","Date":"Wed, 30 Jul 2025 12:23:09 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tHan-Lin Chen <hanlinchen@chromium.org>,\n\tHarvey Yang <chenghaoyang@chromium.org>","Subject":"Re: [PATCH v2 1/2] libcamera: utils: Add scope_exit class","Message-ID":"<20250730092309.GB17990@pendragon.ideasonboard.com>","References":"<20250729162101.13836-1-laurent.pinchart@ideasonboard.com>\n\t<20250729162101.13836-2-laurent.pinchart@ideasonboard.com>\n\t<e9441b57-184b-45eb-9624-eae149a80f5f@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<e9441b57-184b-45eb-9624-eae149a80f5f@ideasonboard.com>","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>"}}]