0Pricing
C++ Academy · Lesson

Transforming Types

remove_const, decay, and more.

Type Transformations

Besides querying, <type_traits> can produce new types from old ones. These traits expose a member type ::type, with a _t shortcut in C++14+.

remove_const

std::remove_const_t<const int> yields int. Useful when you need a mutable version of a type.

#include <iostream>
#include <type_traits>

int main() {
    using T = std::remove_const_t<const int>;
    std::cout << std::is_same_v<T, int> << "\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