W3cubDocs

/C++

std::type_identity

Defined in header <type_traits>
template< class T >
struct type_identity;
(since C++20)

Provides the member typedef type that names T (i.e., the identity transformation).

Member types

Name Definition
type T

Helper types

template< class T >
using type_identity_t = typename type_identity<T>::type;
(since C++20)

Possible implementation

template< class T >
struct type_identity {
    using type = T;
};

Notes

type_identity can be used to block template argument deduction:

template<class T>
void f(T, T);
 
template<class T>
void g(T, std::type_identity_t<T>);
 
f(4.2, 0); // error, deduced conflicting types for 'T'
g(4.2, 0); // OK, calls g<double>

Example

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/types/type_identity