From 5c71df927ddaaa01204bff1e647c9d2bf653d95f Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 11 Nov 2024 13:02:30 +0200 Subject: libcamera: yaml_parser: Use std::from_chars() std::from_chars(), introduced in C++17, is a fast, locale-independent string-to-arithmetic conversion function. The C++ standard library provides overloads for all integer types, making it a prime candidate to replace the manual handling of integer sizes in the YamlParser string to integer conversion. Compared to std::strtol(), std::from_chars() doesn't recognize the '0x' prefix or '+' prefix, and doesn't ignore leading white space. As the YamlParser doesn't require those features, std::from_chars() can be used safely, reducing the amount of code. C++17 also requires the standard C++ library to provide overloads for floating-point types, but libc++ does not implement those. The float and bool implementations of YamlParser::Getter::get() are therefore kept as-is. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- include/libcamera/internal/yaml_parser.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index de452844..8c791656 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -224,7 +224,7 @@ private: Empty, }; - template + template struct Getter { std::optional get(const YamlObject &obj) const; }; -- cgit v1.2.1