skip to content
Ivan's wiki
Site Tools
Search
Tools
Show pagesource
Backlinks
Recent Changes
Media Manager
Sitemap
>
Recent Changes
Media Manager
Sitemap
hpp-type-traits
This page is read only. You can view the source, but not change it.
# <type_traits> **[<type_traits>](https://en.cppreference.com/w/cpp/header/type_traits)** provides type introspection and transformation templates: `std::is_integral<T>`, `std::is_pointer<T>`, `std::remove_reference<T>`, `std::enable_if<Cond, T>`, and many others. Use them to write generic code that adapts to type properties at compile time. Concepts (C++20) often replace manual type trait checks, but traits remain useful for SFINAE and metaprogramming. This example queries type traits to detect whether types are integral or pointer types, enabling conditional behavior. ```cpp // compile: g++ -std=c++11 -o typetraitsexample typetraitsexample.cpp // run: ./typetraitsexample // description: type trait checks #include <type_traits> #include <iostream> template <typename T> void describe() { if (std::is_integral_v<T>) { std::cout << "integral type\n"; } if (std::is_pointer_v<T>) { std::cout << "pointer type\n"; } } int main() { describe<int>(); describe<int*>(); describe<double>(); return 0; } ```
Page Tools
Show pagesource
Backlinks
Back to top