Message ID | 20250606164156.1442682-5-barnabas.pocze@ideasonboard.com |
---|---|
State | New |
Headers | show |
Series |
|
Related | show |
Hi Barnabás On Fri, Jun 06, 2025 at 06:41:37PM +0200, Barnabás Pőcze wrote: > `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> > --- > 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 >
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 */
`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> --- include/libcamera/base/details/cxx20.h | 3 +++ 1 file changed, 3 insertions(+)