skip to content
Ivan's wiki
Site Tools
Search
Tools
Show pagesource
Backlinks
Recent Changes
Media Manager
Sitemap
>
Recent Changes
Media Manager
Sitemap
hpp-typeinfo
This page is read only. You can view the source, but not change it.
# <typeinfo> **[<typeinfo>](https://en.cppreference.com/w/cpp/header/typeinfo)** provides `std::type_info`, an object that holds type metadata available at runtime (via `typeid()`). You can compare `type_info` objects, get a name (though it's mangled), or use `before()` to sort types. Use it for runtime type identification; wrap it in `std::type_index` if you need a hashable version. This example uses typeid to get runtime type information and check if values match specific types. ```cpp // compile: g++ -std=c++11 -o typeinfoexample typeinfoexample.cpp // run: ./typeinfoexample // description: runtime type identification #include <typeinfo> #include <iostream> void identify(int) { std::cout << "got int\n"; } void identify(double) { std::cout << "got double\n"; } int main() { const std::type_info& ti = typeid(42); std::cout << "typeid(42): " << ti.name() << "\n"; if (typeid(int) == typeid(42)) { std::cout << "42 is int\n"; } return 0; } ```
Page Tools
Show pagesource
Backlinks
Back to top