skip to content
Ivan's wiki
Site Tools
Search
Tools
Show pagesource
Backlinks
Recent Changes
Media Manager
Sitemap
>
Recent Changes
Media Manager
Sitemap
hpp-typeindex
This page is read only. You can view the source, but not change it.
# <typeindex> **[<typeindex>](https://en.cppreference.com/w/cpp/header/typeindex)** provides `std::type_index`, a hashable wrapper around `std::type_info` from `<typeinfo>`. Use it to store types in containers like `std::map` or `std::unordered_map`. You rarely need this; it's mainly useful for dynamic type dispatch or plugin systems. This example uses type_index as a map key to associate types with their string names. ```cpp // compile: g++ -std=c++11 -o typeindexexample typeindexexample.cpp // run: ./typeindexexample // description: use types as map keys #include <typeindex> #include <map> #include <iostream> int main() { std::map<std::type_index, std::string> type_names; type_names[std::type_index(typeid(int))] = "integer"; type_names[std::type_index(typeid(double))] = "floating point"; std::cout << "int is: " << type_names[std::type_index(typeid(int))] << "\n"; return 0; } ```
Page Tools
Show pagesource
Backlinks
Back to top