[PATCH v1] libcamera: yaml_parser: Make default value templated in `get()`

Kieran Bingham kieran.bingham at ideasonboard.com
Mon May 20 11:53:36 CEST 2024


Quoting Barnabás Pőcze (2024-05-20 05:02:50)
> 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 <pobrn at protonmail.com>

This looks and sounds good to me.

Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>

> ---
>  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<T> get() const;
>  
> -       template<typename T>
> -       T get(const T &defaultValue) const
> +       template<typename T, typename U>
> +       T get(U &&defaultValue) const
>         {
> -               return get<T>().value_or(defaultValue);
> +               return get<T>().value_or(std::forward<U>(defaultValue));
>         }
>  
>  #ifndef __DOXYGEN__
> -- 
> 2.45.1
> 
>


More information about the libcamera-devel mailing list