std::type_identity(3)
π std::type_identity(3) β C++ Standard Libary π
okay so bestie, this is the manual page for std::type_identity(3) from the C++ Standard Libary. Let's get into it.
β¨ NAME β¨
std::type_identity - std::type_identity
π¦ Synopsis π¦
Defined in header <type_traits>:
template< class T > (since C++20)
struct type_identity;
It provides the member typedef type that names T (i.e., the identity transformation).
bestie, if the program adds specializations for std::type_identity, the behavior is undefined. Like, do not do that. π
πΈ Member types πΈ
- Name:
typeβ Definition:T
π Helper types π
template< class T > (since C++20)
using type_identity_t = type_identity<T>::type;
π§ Possible implementation π§
template<class T>
struct type_identity { using type = T; };
π Notes π
std::type_identity can be used to establish non-deduced contexts in template argument deduction. slay.
Feature-test macro vibes:
- Feature-test macro:
__cpp_lib_type_identity - Value:
201806L - Std:
(C++20) - Feature:
std::type_identity
π₯ Example π₯
Run this code (// Run this code):
#include <iostream>
#include <type_traits>
template<class T>
T foo(T a, T b) { return a + b; }
template<class T>
T bar(T a, std::type_identity_t<T> b) { return a + b; }
int main()
{
// 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 π
- identity β function object that returns its argument unchanged β
(C++20)β(class)
that's the whole vibe, bestie π«Ά β source/version: http://cppreference.com, date: 2024.06.10. periodt π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms