What’s the deal with std::type_identity?

thumbnail

Summary

  • std::type_identity in C++20 is a type wrapper that allows a type to be used without participating in type deduction.
  • It is commonly used to control type deduction in function templates, such as ensuring that one parameter's type is determined by another parameter's type.
  • std::type_identity can be scoped to specific parts of a type and can be used in various scenarios to control template type deduction.
  • It can also be used to force explicit specification of template types and to suppress class template argument deduction (CTAD).

Overall, std::type_identity is a useful tool in C++ for managing type deduction and ensuring specific type behavior in templates.