0Pricing
C++ Academy · Lesson

Querying Types

Inspect types at compile time.

What Are Type Traits?

The <type_traits> header lets you ask questions about types at compile time. Each trait is a template that exposes a constant ::value or a member type.

is_integral

std::is_integral<T>::value is true for integer types like int and char, false otherwise.

#include <iostream>
#include <type_traits>

int main() {
    std::cout << std::is_integral<int>::value << "\n";
    std::cout << std::is_integral<double>::value << "\n";
    return 0;
}

All lessons in this course

  1. Querying Types
  2. Transforming Types
  3. Conditional Logic
  4. Writing Custom Traits
← Back to C++ Academy