[RFC PATCH 8/8] [DNI] libcamera: yaml_parser: Replace std::string reference with std::string_view

Laurent Pinchart laurent.pinchart at ideasonboard.com
Mon Dec 16 00:02:06 CET 2024


This showcases how std::string_view can replace a const std::string
reference as a key in a std::map. The patch does not compile due the
lack of heterogenous lookup functions for containers (see
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2363r5.html),
and must therefore not be integrated.

Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
 include/libcamera/internal/yaml_parser.h | 2 +-
 src/libcamera/yaml_parser.cpp            | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h
index 8c79165659469f65..b92c958f0ec59df4 100644
--- a/include/libcamera/internal/yaml_parser.h
+++ b/include/libcamera/internal/yaml_parser.h
@@ -124,7 +124,7 @@ public:
 	class DictIterator : public Iterator<DictIterator>
 	{
 	public:
-		using value_type = std::pair<const std::string &, const YamlObject &>;
+		using value_type = std::pair<std::string_view, const YamlObject &>;
 		using pointer = value_type *;
 		using reference = value_type &;
 
diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp
index 5ca5fb8235b5e761..555ad03c8dee3f3a 100644
--- a/src/libcamera/yaml_parser.cpp
+++ b/src/libcamera/yaml_parser.cpp
@@ -312,7 +312,7 @@ template std::optional<std::vector<Size>> YamlObject::getList<Size>() const;
  * iteration order is not specified.
  *
  * The iterator's value_type is a
- * <em>std::pair<const std::string &, const \ref YamlObject &></em>.
+ * <em>std::pair<std::string_view, const \ref YamlObject &></em>.
  *
  * If the YamlObject is not of Dictionary type, the returned adapter operates
  * as an empty container.
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list