[v4,04/22] libcamera: base: cxx20: Add `type_identity{,_t}`
diff mbox series

Message ID 20260106165754.1759831-5-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • libcamera: Add `MetadataList`
Related show

Commit Message

Barnabás Pőcze Jan. 6, 2026, 4:57 p.m. UTC
`type_identity_t` can be used to force non-deduced contexts
in templates, such as:

  void f(T x, type_identity_t<T> y)

when calling `f(1u, 2)`, without `type_identity_t`, the compiler
could not unambiguously deduce `T` (unsigned int vs int). However,
with `type_identity_t`, the type of the argument passed to `y`
will not be used to deduce `T`, only the argument passed to `x`.

See https://en.cppreference.com/w/cpp/types/type_identity

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 include/libcamera/base/internal/cxx20.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Patch
diff mbox series

diff --git a/include/libcamera/base/internal/cxx20.h b/include/libcamera/base/internal/cxx20.h
index 70a43f83c..1f4caf56f 100644
--- a/include/libcamera/base/internal/cxx20.h
+++ b/include/libcamera/base/internal/cxx20.h
@@ -15,4 +15,28 @@ 
 
 namespace libcamera::internal::cxx20 {
 
+/**
+ * \internal
+ * \brief std::type_identity
+ *
+ * Implementation of std::type_identity for C++17.
+ */
+template<typename T> struct type_identity {
+	/**
+	 * \internal
+	 * \brief std::type_identity<T>::type
+	 *
+	 * Type alias matching the template parameter.
+	 */
+	using type = T;
+};
+
+/**
+ * \internal
+ * \brief std::type_identity_t
+ *
+ * Implementation of std::type_identity_t for C++17.
+ */
+template<typename T> using type_identity_t = typename type_identity<T>::type;
+
 } /* namespace libcamera::internal::cxx20 */