A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/typeindex/type_index/ below:

class

<typeindex>

std::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
(constructor)
Construct type_index (public member function)
hash_code
Get type hash code (public member function)
name
Get type name (public member function)
(relational operators)
type_index operators (public member function)

Non-member class specializations
hash<type_index>
Hash for type_index (class template specialization)

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


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