libcamera: yaml_parser: Make default value templated in get()

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 <pobrn@protonmail.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Barnabás Pőcze
2024-06-13 02:13:36 +03:00
committed by Laurent Pinchart
parent d9c6835e23
commit 20b8538a19
2 changed files with 4 additions and 4 deletions
+3 -3
View File
@@ -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__
+1 -1
View File
@@ -104,7 +104,7 @@ std::size_t YamlObject::size() const
*/
/**
* \fn template<typename T> YamlObject::get<T>(const T &defaultValue) const
* \fn template<typename T, typename U> YamlObject::get<T>(U &&defaultValue) const
* \brief Parse the YamlObject as a \a T value
* \param[in] defaultValue The default value when failing to parse
*