C++ Logo

std-discussion

Advanced search

Re: What's the usage of type_identity?

From: Peter Sommerlad (C++) <"Peter>
Date: Mon, 21 Dec 2020 14:16:44 +0100
Akira,

it prevents type deduction of template parameter U.

see also
https://en.cppreference.com/w/cpp/types/type_identity

with a better example to show where it is used to prevent conflicts in
argument deduction.

However, I cannot answer your second question for sure.

Regards
Peter.

Akira Takahashi via Std-Discussion wrote on 18.12.20 07:04:
> Hi,
> I have a question.
>
> P1021R3 Filling holes in Class Template Argument Deduction
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1021r3.html
>
> P1814R0 Wording for Class Template Argument Deduction for Alias Templates
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1814r0.html
>
> template <class T, class U>
> struct C {
> C(T, U); // #1
> };
>
> template <class T, class U>
> C(T, U) -> C<T, std::type_identity_t<U>>; #2 THIS
>
> What's the usage of type_identity?
> Why not directly use a constructor?
>
> Thanks,
> Akira
>
>


-- 
Peter Sommerlad
Better Software: Consulting, Training, Reviews
Modern, Safe & Agile C++
peter.cpp_at_[hidden]
+41 79 432 23 32

Received on 2020-12-21 07:16:50