From 20b8538a197c45597eecf5c7a51058263e816eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Wed, 12 Jun 2024 22:46:16 +0000 Subject: libcamera: yaml_parser: Make default value templated in `get()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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` and the default value comes from a string literal, as the default value string would always be constructed otherwise, even if not needed. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Laurent Pinchart --- include/libcamera/internal/yaml_parser.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include') 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__ -- cgit v1.2.1