[libcamera-devel] [PATCH v6 6/8] libcamera: v4l2_pixelformat: Implement std::hash specialization

Jacopo Mondi jacopo at jmondi.org
Wed Aug 3 13:26:38 CEST 2022


From: Laurent Pinchart <laurent.pinchart at ideasonboard.com>

Inject a specialization of std::hash<> for the V4L2PixelFormat class in
the std namespace to make it possible to store instances of the class in
the std::unordered_map and std::unordered_set containers.

Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo at jmondi.org>
Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
 include/libcamera/internal/v4l2_pixelformat.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/include/libcamera/internal/v4l2_pixelformat.h b/include/libcamera/internal/v4l2_pixelformat.h
index d5400f90a67e..34d283db44f4 100644
--- a/include/libcamera/internal/v4l2_pixelformat.h
+++ b/include/libcamera/internal/v4l2_pixelformat.h
@@ -8,6 +8,7 @@
 
 #pragma once
 
+#include <functional>
 #include <ostream>
 #include <stdint.h>
 #include <string>
@@ -55,3 +56,15 @@ private:
 std::ostream &operator<<(std::ostream &out, const V4L2PixelFormat &f);
 
 } /* namespace libcamera */
+
+namespace std {
+
+template<>
+struct hash<libcamera::V4L2PixelFormat> {
+	size_t operator()(libcamera::V4L2PixelFormat const &format) const noexcept
+	{
+		return format.fourcc();
+	}
+};
+
+} /* namespace std */
-- 
2.37.1



More information about the libcamera-devel mailing list