class
<typeindex>

std::type_index

class type_index;
Type index
Class that wraps a type_info object so that it can be copied (copy-constructed and copy-assigned) and/or be used used as index by means of a standard hash function.

The class provides direct access to the name and hash_code members of type_info.

Member functions


Non-member class specializations


Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// type_index example #include <iostream> // std::cout #include <typeinfo> // operator typeid #include <typeindex> // std::type_index #include <unordered_map> // std::unordered_map #include <string> // std::string struct C {}; int main() { std::unordered_map<std::type_index,std::string> mytypes; mytypes[typeid(int)]="Integer type"; mytypes[typeid(double)]="Floating-point type"; mytypes[typeid(C)]="Custom class named C"; std::cout << "int: " << mytypes[typeid(int)] << '\n'; std::cout << "double: " << mytypes[typeid(double)] << '\n'; std::cout << "C: " << mytypes[typeid(C)] << '\n'; return 0; }

Output:
int: Integer type double: Floating-point type C: Custom class named C