{"id":20271,"url":"https://patchwork.libcamera.org/api/1.1/patches/20271/?format=json","web_url":"https://patchwork.libcamera.org/patch/20271/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20240612224614.35807-1-pobrn@protonmail.com>","date":"2024-06-12T22:46:16","name":"[v2] libcamera: yaml_parser: Make default value templated in `get()`","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"817e5d95a5e2191ba070216e176a7878acd3df4f","submitter":{"id":133,"url":"https://patchwork.libcamera.org/api/1.1/people/133/?format=json","name":"Pőcze Barnabás","email":"pobrn@protonmail.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/20271/mbox/","series":[{"id":4385,"url":"https://patchwork.libcamera.org/api/1.1/series/4385/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4385","date":"2024-06-12T22:46:16","name":"[v2] libcamera: yaml_parser: Make default value templated in `get()`","version":2,"mbox":"https://patchwork.libcamera.org/series/4385/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/20271/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/20271/checks/","tags":{},"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 81793C3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 12 Jun 2024 22:46:22 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3439265469;\n\tThu, 13 Jun 2024 00:46:21 +0200 (CEST)","from mail-40135.protonmail.ch (mail-40135.protonmail.ch\n\t[185.70.40.135])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9BD3A65446\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Jun 2024 00:46:19 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=protonmail.com header.i=@protonmail.com\n\theader.b=\"EUuVTQqI\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1718232378; x=1718491578;\n\tbh=6/49QokyRxShOovNVxjF1Bb5VGTnzs7Zzqk7ZY1gFBg=;\n\th=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date:\n\tSubject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector;\n\tb=EUuVTQqI+IoV52ThZRo4wA64V2ukfNwmZ1YZyemr6ac4x/4oYL6veIR/oOLG3iDTB\n\tOrKaO71ne9pe3ChoEc1dtM13MotzzBPEVo8NreGoe4thCAhY5GUyG2/a9qS5e7kG2W\n\tsmzxBQHbY1jisjmt7UUknmJ/c42VhOTtYdyoNmHwH54omnMSOnL8fuPtc44GTpW2cR\n\tHyRT7yoTGRSsimVTgT7m1TQE0JQBnGi8v/ESJi8Zt6R0DFLUKek6U/ZSU1EEgadr2X\n\t8Jj1P4pdJsPgvMPue/SkI/0yXugqRM7QIBaNG5bH9puOPAK7vpZVNWl9l47x7YOPMP\n\tCwSJ6nbsmFBNg==","Date":"Wed, 12 Jun 2024 22:46:16 +0000","To":"libcamera-devel@lists.libcamera.org","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Subject":"[PATCH v2] libcamera: yaml_parser: Make default value templated in\n\t`get()`","Message-ID":"<20240612224614.35807-1-pobrn@protonmail.com>","Feedback-ID":"20568564:user:proton","X-Pm-Message-ID":"c55b582ca106d76cfd2ebbe2670407e86fbb28c9","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"quoted-printable","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>"},"content":"This way the construction of the default value of type `T`\ncan be delayed until it is really needed, which is useful,\nfor example when `T == std::string` and the default value comes\nfrom a string literal, as the default value string would always\nbe constructed otherwise, even if not needed.\n\nSigned-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n---\nChanges 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--\n2.45.2","diff":"diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h\nindex 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__\ndiff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\nindex 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","prefixes":["v2"]}