[RFC PATCH v1 04/23] libcamera: base: cxx20: Add `type_identity{, _t}`
Barnabás Pőcze
barnabas.pocze at ideasonboard.com
Fri Jun 6 18:41:37 CEST 2025
`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 at ideasonboard.com>
---
include/libcamera/base/details/cxx20.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/include/libcamera/base/details/cxx20.h b/include/libcamera/base/details/cxx20.h
index 0d6173d1b..2d26db53e 100644
--- a/include/libcamera/base/details/cxx20.h
+++ b/include/libcamera/base/details/cxx20.h
@@ -9,4 +9,7 @@
namespace libcamera::details::cxx20 {
+template<typename T> struct type_identity { using type = T; };
+template<typename T> using type_identity_t = typename type_identity<T>::type;
+
} /* namespace libcamera::details::cxx20 */
--
2.49.0
More information about the libcamera-devel
mailing list