From patchwork Mon May 20 04:02:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 20078 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id EE6CEBD78E for ; Mon, 20 May 2024 04:03:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0C37D6347F; Mon, 20 May 2024 06:03:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="I6FSYUJH"; dkim-atps=neutral Received: from mail-40133.protonmail.ch (mail-40133.protonmail.ch [185.70.40.133]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 068AD6346B for ; Mon, 20 May 2024 06:02:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1716177777; x=1716436977; bh=t8rTyrVK76NAH6TBaWUfsi+EvsZbnNeIQ3X9uTp7Cvo=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=I6FSYUJHeUWTfaQrXKfWy/LU2Fwsnl5KJCFX2cpDX4aHdA0nsqDXP3BjnwU6xAQMX QOL5EkIZgbsOi2oV4k2KSTInCDI4GbUbUNRBUUw1xnVd92vmL0hJxQoUeVdYOuSO8F NVJQ1FoHzABXEzxYiOa+rg5cqDPMobS5uttWCY88ceWcNf/BCu1wbw9QHuaekzhb1g DaX3FOYF1zUck5kxiqllkmHIhqgATF14AuJR3/ZGOJECGyGEfH4Pji36xR/6lauE56 +G/ULBuj/dmxJ9XO0iQvQAf2l/16Xb5T9TfeJPdfyF1pIfE/koU5BxViT7N6TXP4S1 nKtJZ7AzoU7IQ== Date: Mon, 20 May 2024 04:02:50 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v1] libcamera: yaml_parser: Make default value templated in `get()` Message-ID: <20240520040249.209200-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: fac5e61cc0ed682f9bdc3a4d1f5ea9541e820778 MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This way the construction of the default value of type `T` can be delayed until it is really needed, which is useful, for example when `T == std::string`, as the default value string would always be constructed otherwise. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham --- include/libcamera/internal/yaml_parser.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index b6979d73..3ac27e06 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -179,10 +179,10 @@ public: #endif std::optional get() const; - template - T get(const T &defaultValue) const + template + T get(U &&defaultValue) const { - return get().value_or(defaultValue); + return get().value_or(std::forward(defaultValue)); } #ifndef __DOXYGEN__