diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2024-11-11 13:02:30 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2024-11-13 15:38:18 +0200 |
commit | 5c71df927ddaaa01204bff1e647c9d2bf653d95f (patch) | |
tree | f9aaf31f53f0209b89a08d5474c1f999f695b233 /include | |
parent | 6d9baefca8a7e8d7e74dcd03e6cd06a30f2c1601 (diff) |
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 <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/libcamera/internal/yaml_parser.h | 2 |
1 files changed, 1 insertions, 1 deletions
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<typename T> + template<typename T, typename Enable = void> struct Getter { std::optional<T> get(const YamlObject &obj) const; }; |