Type support (basic types, RTTI, type traits) - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# Type support (basic types, RTTI, type traits)

From cppreference.com
< cpp

(See also `type` for type system overview)

### [edit] Basic types

#### [edit] Fundamental types defined by the language

#### [edit] Additional basic types and macros

Defined in header `<cstddef>`
size_t | unsigned integer type returned by the `sizeof` operator (typedef) [edit]
ptrdiff_t | signed integer type returned when subtracting two pointers (typedef) [edit]
nullptr_t (C++11) | the type of the null pointer literal `nullptr` (typedef) [edit]
NULL | implementation-defined null pointer constant (macro constant) [edit]
max_align_t (C++11) | POD type with alignment requirement as great as any other scalar type (typedef) [edit]
offsetof | byte offset from the beginning of a standard-layout type to specified member (function macro) [edit]
byte (C++17) | the byte type (enum) [edit]
Defined in header `<cstdbool>`
__bool_true_false_are_defined (C++11) | C compatibility macro constant, expands to integer constant 1 (macro constant)
Defined in header `<cstdalign>`
__alignas_is_defined (C++11) | C compatibility macro constant, expands to integer constant 1 (macro constant)

#### [edit] Fixed width integer types (since C++11)

### [edit] Numeric limits

Defined in header `<limits>`
numeric_limits | provides an interface to query properties of all fundamental numeric types. (class template) [edit]

#### [edit] C numeric limits interface

### [edit] Runtime type identification

Defined in header `<typeinfo>`
type_info | contains some type's information, generated by the implementation. This is the class returned by the typeid operator. (class) [edit]
bad_typeid | exception that is thrown if an argument in a typeid expression is null (class) [edit]
bad_cast | exception that is thrown by an invalid `dynamic_cast` expression, i.e. a cast of reference type fails (class) [edit]
Defined in header `<typeindex>`
type_index (C++11) | wrapper around a `type_info` object, that can be used as index in associative and unordered associative containers (class) [edit]

### [edit] Type traits (since C++11)

Type traits defines a compile-time template-based interface to query or modify the properties of types.

Attempting to specialize a template defined in the `<type_traits>` header results in undefined behavior, except that std::common_type may be specialized as described in its description.

A template defined in the `<type_traits>` header may be instantiated with an incomplete type unless otherwise specified, notwithstanding the general prohibition against instantiating standard library templates with incomplete types.

#### [edit] Type properties

Defined in header `<type_traits>`
##### Primary type categories
is_void (C++11) | checks if a type is void (class template) [edit]
is_null_pointer (C++14) | checks if a type is std::nullptr_t (class template) [edit]
is_integral (C++11) | checks if a type is integral type (class template) [edit]
is_floating_point (C++11) | checks if a type is floating-point type (class template) [edit]
is_array (C++11) | checks if a type is an array type (class template) [edit]
is_enum (C++11) | checks if a type is an enumeration type (class template) [edit]
is_union (C++11) | checks if a type is an union type (class template) [edit]
is_class (C++11) | checks if a type is a non-union class type (class template) [edit]
is_function (C++11) | checks if a type is a function type (class template) [edit]
is_pointer (C++11) | checks if a type is a pointer type (class template) [edit]
is_lvalue_reference (C++11) | checks if a type is lvalue reference (class template) [edit]
is_rvalue_reference (C++11) | checks if a type is rvalue reference (class template) [edit]
is_member_object_pointer (C++11) | checks if a type is a pointer to a non-static member object (class template) [edit]
is_member_function_pointer (C++11) | checks if a type is a pointer to a non-static member function (class template) [edit]
##### Composite type categories
is_fundamental (C++11) | checks if a type is fundamental type (class template) [edit]
is_arithmetic (C++11) | checks if a type is arithmetic type (class template) [edit]
is_scalar (C++11) | checks if a type is scalar type (class template) [edit]
is_object (C++11) | checks if a type is object type (class template) [edit]
is_compound (C++11) | checks if a type is compound type (class template) [edit]
is_reference (C++11) | checks if a type is either lvalue reference or rvalue reference (class template) [edit]
is_member_pointer (C++11) | checks if a type is a pointer to a non-static member function or object (class template) [edit]
##### Type properties
is_const (C++11) | checks if a type is const-qualified (class template) [edit]
is_volatile (C++11) | checks if a type is volatile-qualified (class template) [edit]
is_trivial (C++11) | checks if a type is trivial (class template) [edit]
is_trivially_copyable (C++11) | checks if a type is trivially copyable (class template) [edit]
is_standard_layout (C++11) | checks if a type is standard-layout type (class template) [edit]
is_pod (C++11) | checks if a type is plain-old data (POD) type (class template) [edit]
is_literal_type (C++11)(deprecated in C++17) | checks if a type is literal type (class template) [edit]
has_unique_object_representations (C++17) | checks if every bit in the type's object representation contributes to its value (class template) [edit]
is_empty (C++11) | checks if a type is class (but not union) type and has no data (class template) [edit]
is_polymorphic (C++11) | checks if a type is polymorphic class type (class template) [edit]
is_abstract (C++11) | checks if a type is abstract class type (class template) [edit]
is_final (C++14) | checks if a type is a final class type (class template) [edit]
is_aggregate (C++17) | checks if a type is an aggregate type (class template) [edit]
is_signed (C++11) | checks if a type is signed arithmetic type (class template) [edit]
is_unsigned (C++11) | checks if a type is unsigned arithmetic type (class template) [edit]

##### Supported operations
is_constructibleis_trivially_constructibleis_nothrow_constructible (C++11)(C++11)(C++11) | checks if a type has a constructor for specific arguments (class template) [edit]
is_default_constructibleis_trivially_default_constructibleis_nothrow_default_constructible (C++11)(C++11)(C++11) | checks if a type has a default constructor (class template) [edit]
is_copy_constructibleis_trivially_copy_constructibleis_nothrow_copy_constructible (C++11)(C++11)(C++11) | checks if a type has a copy constructor (class template) [edit]
is_move_constructibleis_trivially_move_constructibleis_nothrow_move_constructible (C++11)(C++11)(C++11) | checks if a type can be constructed from an rvalue reference (class template) [edit]
is_assignableis_trivially_assignableis_nothrow_assignable (C++11)(C++11)(C++11) | checks if a type has a assignment operator for a specific argument (class template) [edit]
is_copy_assignableis_trivially_copy_assignableis_nothrow_copy_assignable (C++11)(C++11)(C++11) | checks if a type has a copy assignment operator (class template) [edit]
is_move_assignableis_trivially_move_assignableis_nothrow_move_assignable (C++11)(C++11)(C++11) | checks if a type has a move assignment operator (class template) [edit]
is_destructibleis_trivially_destructibleis_nothrow_destructible (C++11)(C++11)(C++11) | checks if a type has a non-deleted destructor (class template) [edit]
has_virtual_destructor (C++11) | checks if a type has a virtual destructor (class template) [edit]
is_swappable_withis_swappableis_nothrow_swappable_withis_nothrow_swappable (C++17)(C++17)(C++17)(C++17) | checks if objects of a type can be swapped with objects of same or different type (class template) [edit]

##### Property queries
alignment_of (C++11) | obtains the type's alignment requirements (class template) [edit]
rank (C++11) | obtains the number of dimensions of an array type (class template) [edit]
extent (C++11) | obtains the size of an array type along a specified dimension (class template) [edit]

##### Type relationships
is_same (C++11) | checks if two types are the same (class template) [edit]
is_base_of (C++11) | checks if a type is derived from the other type (class template) [edit]
is_convertible (C++11) | checks if a type can be converted to the other type (class template) [edit]
is_invocableis_invocable_ris_nothrow_invocableis_nothrow_invocable_r (C++17) | checks if a type can be invoked (as if by std::invoke) with the given argument types (class template) [edit]

#### [edit] Type modifications

Type modification templates create new type definitions by applying modifications on a template parameter. The resulting type can then be accessed through `type` member typedef.

Defined in header `<type_traits>`
##### Const-volatility specifiers
remove_cvremove_constremove_volatile (C++11)(C++11)(C++11) | removes const or/and volatile specifiers from the given type (class template) [edit]
add_cvadd_constadd_volatile (C++11)(C++11)(C++11) | adds const or/and volatile specifiers to the given type (class template) [edit]
##### References
remove_reference (C++11) | removes reference from the given type (class template) [edit]
add_lvalue_referenceadd_rvalue_reference (C++11)(C++11) | adds lvalue or rvalue reference to the given type (class template) [edit]
##### Pointers
remove_pointer (C++11) | removes pointer from the given type (class template) [edit]
add_pointer (C++11) | adds pointer to the given type (class template) [edit]
##### Sign modifiers
make_signed (C++11) | makes the given integral type signed (class template) [edit]
make_unsigned (C++11) | makes the given integral type unsigned (class template) [edit]
##### Arrays
remove_extent (C++11) | removes one extent from the given array type (class template) [edit]
remove_all_extents (C++11) | removes all extents from the given array type (class template) [edit]

#### [edit] Miscellaneous transformations

Defined in header `<type_traits>`
aligned_storage (C++11) | defines the type suitable for use as uninitialized storage for types of given size (class template) [edit]
aligned_union (C++11) | defines the type suitable for use as uninitialized storage for all given types (class template) [edit]
decay (C++11) | applies type transformations as when passing a function argument by value (class template) [edit]
enable_if (C++11) | hides a function overload or template specialization based on compile-time boolean (class template) [edit]
conditional (C++11) | chooses one type or another based on compile-type boolean (class template) [edit]
common_type (C++11) | determines the common type of a group of types (class template) [edit]
underlying_type (C++11) | obtains the underlying integer type for a given enumeration type (class template) [edit]
result_ofinvoke_result (C++11)(deprecated in C++17)(C++17) | deduces the result type of invoking a callable object with a set of arguments (class template) [edit]
void_t (C++17) | void variadic alias template (alias template) [edit]

#### [edit] Operations on traits

Defined in header `<type_traits>`
conjunction (C++17) | variadic logical AND metafunction (class template) [edit]
disjunction (C++17) | variadic logical OR metafunction (class template) [edit]
negation (C++17) | logical NOT metafunction (class template) [edit]

#### [edit] Helper classes

Defined in header `<type_traits>`
integral_constantbool_constant (C++11)(C++17) | compile-time constant of specified type with specified value (class template) [edit]

Two specializations of std::integral_constant for the type bool are provided:

Defined in header `<type_traits>`
Type | Definition
`true_type` | std::integral_constant<bool, true>
`false_type` | std::integral_constant<bool, false>

### [edit] See also

C documentation for Type support library

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/types&oldid=90849"