From cppreference.com
template<classT>structtype_identity;(since C++20)Provides the member typedef type that names T (i.e., the identity transformation).
If the program adds specializations for std::type_identity, the behavior is undefined.
Member types
Name Definition typeTHelper types
template<classT>usingtype_identity_t=type_identity<T>::type;(since C++20)Possible implementation
template<classT>structtype_identity{usingtype=T;};Notes
std::type_identity can be used to establish
in template argument deduction.
macroValueStdFeature
(C++20)std::type_identityExample
Run this code
#include<iostream>#include<type_traits>template<classT>Tfoo(Ta,Tb){returna+b;}template<classT>Tbar(Ta,std::type_identity_t<T>b){returna+b;}intmain(){// foo(4.2, 1); // error, deduced conflicting types for 'T'std::cout<<bar(4.2,1)<<'\n';// OK, calls bar<double>}Output:
5.2 See also
(C++20)
function object that returns its argument unchanged
(class)