[{"id":29880,"web_url":"https://patchwork.libcamera.org/comment/29880/","msgid":"<20240612231126.GB7291@pendragon.ideasonboard.com>","date":"2024-06-12T23:11:26","subject":"Re: [PATCH v2] libcamera: yaml_parser: Make default value templated\n\tin `get()`","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Barnabás,\n\nThank you for the patch.\n\nOn Wed, Jun 12, 2024 at 10:46:16PM +0000, Barnabás Pőcze wrote:\n> This way the construction of the default value of type `T`\n> can be delayed until it is really needed, which is useful,\n> for example when `T == std::string` and the default value comes\n> from a string literal, as the default value string would always\n> be constructed otherwise, even if not needed.\n> \n> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n> Changes in v2:\n>  * update documentation\n> \n> ---\n>  include/libcamera/internal/yaml_parser.h | 6 +++---\n>  src/libcamera/yaml_parser.cpp            | 2 +-\n>  2 files changed, 4 insertions(+), 4 deletions(-)\n> \n> diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h\n> index b6979d73..3ac27e06 100644\n> --- a/include/libcamera/internal/yaml_parser.h\n> +++ b/include/libcamera/internal/yaml_parser.h\n> @@ -179,10 +179,10 @@ public:\n>  #endif\n>  \tstd::optional<T> get() const;\n> \n> -\ttemplate<typename T>\n> -\tT get(const T &defaultValue) const\n> +\ttemplate<typename T, typename U>\n> +\tT get(U &&defaultValue) const\n>  \t{\n> -\t\treturn get<T>().value_or(defaultValue);\n> +\t\treturn get<T>().value_or(std::forward<U>(defaultValue));\n>  \t}\n> \n>  #ifndef __DOXYGEN__\n> diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\n> index aac9a2bd..b68a44c1 100644\n> --- a/src/libcamera/yaml_parser.cpp\n> +++ b/src/libcamera/yaml_parser.cpp\n> @@ -104,7 +104,7 @@ std::size_t YamlObject::size() const\n>   */\n> \n>  /**\n> - * \\fn template<typename T> YamlObject::get<T>(const T &defaultValue) const\n> + * \\fn template<typename T, typename U> YamlObject::get<T>(U &&defaultValue) const\n>   * \\brief Parse the YamlObject as a \\a T value\n>   * \\param[in] defaultValue The default value when failing to parse\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 49F9BBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 12 Jun 2024 23:11:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2F50365463;\n\tThu, 13 Jun 2024 01:11: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 6438565446\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Jun 2024 01:11:47 +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 ESMTPSA id 7D24C4CF;\n\tThu, 13 Jun 2024 01:11:33 +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=\"dL6s2k6u\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1718233893;\n\tbh=jwd1SiVRzxHW/NSTirp8JMFqt2ABWItRKVOcTQR3UNQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=dL6s2k6u+rKPI0atFN8moSn4ezBl5OQRy5wCIFoNpgULhCza89KeqO+sp4XSodEse\n\tn9j3/Xom1b9ttctbX5gPeWy3L2KJnUxlHMSfLkyP/nXdQ1qjcQvTTKvGqMedBbybDE\n\t0OzYomz/onHA7SUtT2c6H2XlH0njYTEexKrF+jM4=","Date":"Thu, 13 Jun 2024 02:11:26 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v2] libcamera: yaml_parser: Make default value templated\n\tin `get()`","Message-ID":"<20240612231126.GB7291@pendragon.ideasonboard.com>","References":"<20240612224614.35807-1-pobrn@protonmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20240612224614.35807-1-pobrn@protonmail.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>"}},{"id":29881,"web_url":"https://patchwork.libcamera.org/comment/29881/","msgid":"<171823399997.2248009.10741155920833020580@ping.linuxembedded.co.uk>","date":"2024-06-12T23:13:19","subject":"Re: [PATCH v2] libcamera: yaml_parser: Make default value templated\n\tin `get()`","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Barnabás Pőcze (2024-06-12 23:46:16)\n> This way the construction of the default value of type `T`\n> can be delayed until it is really needed, which is useful,\n> for example when `T == std::string` and the default value comes\n> from a string literal, as the default value string would always\n> be constructed otherwise, even if not needed.\n> \n> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n> ---\n> Changes in v2:\n>  * update documentation\n\nThanks - fully green:\n - https://gitlab.freedesktop.org/camera/libcamera/-/pipelines/1199993\n\nI had already provided a tag for this on v1, so I think it still holds:\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n \n> ---\n>  include/libcamera/internal/yaml_parser.h | 6 +++---\n>  src/libcamera/yaml_parser.cpp            | 2 +-\n>  2 files changed, 4 insertions(+), 4 deletions(-)\n> \n> diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h\n> index b6979d73..3ac27e06 100644\n> --- a/include/libcamera/internal/yaml_parser.h\n> +++ b/include/libcamera/internal/yaml_parser.h\n> @@ -179,10 +179,10 @@ public:\n>  #endif\n>         std::optional<T> get() const;\n> \n> -       template<typename T>\n> -       T get(const T &defaultValue) const\n> +       template<typename T, typename U>\n> +       T get(U &&defaultValue) const\n>         {\n> -               return get<T>().value_or(defaultValue);\n> +               return get<T>().value_or(std::forward<U>(defaultValue));\n>         }\n> \n>  #ifndef __DOXYGEN__\n> diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\n> index aac9a2bd..b68a44c1 100644\n> --- a/src/libcamera/yaml_parser.cpp\n> +++ b/src/libcamera/yaml_parser.cpp\n> @@ -104,7 +104,7 @@ std::size_t YamlObject::size() const\n>   */\n> \n>  /**\n> - * \\fn template<typename T> YamlObject::get<T>(const T &defaultValue) const\n> + * \\fn template<typename T, typename U> YamlObject::get<T>(U &&defaultValue) const\n>   * \\brief Parse the YamlObject as a \\a T value\n>   * \\param[in] defaultValue The default value when failing to parse\n>   *\n> --\n> 2.45.2\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 6E860BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 12 Jun 2024 23:13:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1FBC265467;\n\tThu, 13 Jun 2024 01:13:23 +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 446346545D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Jun 2024 01:13:22 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A8CA54CF;\n\tThu, 13 Jun 2024 01:13:08 +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=\"RSbXcvBJ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1718233988;\n\tbh=G9I7QQUMFeLSE6HHtXeedP5FhsjxgG2Z7VT5EcR+vSU=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=RSbXcvBJRHm0uu5ssR4BAfGmJTGgENNM9xdMo1VTv3CmIAosrdSE9cCIjp04H1p5Q\n\tDqqIeVU7CD2Yuje1cNizdgHFsUZfF2GR5e6qQAPThNjZbiN3lY8rKsurXQZidRs9/m\n\tvtlWcnlaJKChI3r9JhZb0yA7WDvhLhZf+zCUX2p4=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20240612224614.35807-1-pobrn@protonmail.com>","References":"<20240612224614.35807-1-pobrn@protonmail.com>","Subject":"Re: [PATCH v2] libcamera: yaml_parser: Make default value templated\n\tin `get()`","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Thu, 13 Jun 2024 00:13:19 +0100","Message-ID":"<171823399997.2248009.10741155920833020580@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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>"}}]