std::type_identity(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– 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