class
<typeindex>
std::type_indexType 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.
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;
}
int: Integer type double: Floating-point type C: Custom class named C
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4