std::type_identity

From cppreference.com
< cpp‎ | types
 
 
 
Type support
Basic types
Fundamental types
Fixed width integer types (C++11)
Numeric limits
C numeric limits interface
Runtime type information
Type traits
Type categories
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Type properties
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)(until C++20)
(C++11)(deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Endian
(C++20)
Constant evaluation context
Supported operations
Relationships and property queries
(C++11)
(C++11)
Type modifications
(C++11)(C++11)(C++11)
Type transformations
(C++11)
(C++11)
(C++17)
(C++11)(until C++20)(C++17)
type_identity
(C++20)
 
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