Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/types"

From cppreference.com
< cpp
(endian goes in type_traits, but not a template.. so it goes under a separate section)
m (remove_cvref)
Line 163: Line 163:
 
{{dsc inc | cpp/types/dsc aligned_union}}
 
{{dsc inc | cpp/types/dsc aligned_union}}
 
{{dsc inc | cpp/types/dsc decay}}
 
{{dsc inc | cpp/types/dsc decay}}
 +
{{dsc inc | cpp/types/dsc remove_cvref}}
 
{{dsc inc | cpp/types/dsc enable_if}}
 
{{dsc inc | cpp/types/dsc enable_if}}
 
{{dsc inc | cpp/types/dsc conditional}}
 
{{dsc inc | cpp/types/dsc conditional}}

Revision as of 14:57, 12 November 2017

 
 
Utilities library
General utilities
Relational operators (deprecated in C++20)
 
Type support
 

(See also type for type system overview)

Contents

Basic types

Fundamental types defined by the language

Additional basic types and macros

Defined in header <cstddef>
unsigned integer type returned by the sizeof operator
(typedef) [edit]
signed integer type returned when subtracting two pointers
(typedef) [edit]
(C++11)
the type of the null pointer literal nullptr
(typedef) [edit]
implementation-defined null pointer constant
(macro constant) [edit]
trivial type with alignment requirement as great as any other scalar type
(typedef) [edit]
byte offset from the beginning of a standard-layout type to specified member
(function macro) [edit]
(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)

Fixed width integer types (since C++11)

Numeric limits

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

C numeric limits interface

Runtime type identification

Defined in header <typeinfo>
contains some type’s information, the class returned by the typeid operator
(class) [edit]
exception that is thrown if an argument in a typeid expression is null
(class) [edit]
exception that is thrown by an invalid dynamic_cast expression, i.e. a cast of reference type fails
(class) [edit]
Defined in header <typeindex>
wrapper around a type_info object, that can be used as index in associative and unordered associative containers
(class) [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.

Type properties

Defined in header <type_traits>
Primary type categories
(C++11)
checks if a type is void
(class template) [edit]
checks if a type is std::nullptr_t
(class template) [edit]
checks if a type is an integral type
(class template) [edit]
checks if a type is a floating-point type
(class template) [edit]
(C++11)
checks if a type is an array type
(class template) [edit]
(C++11)
checks if a type is an enumeration type
(class template) [edit]
(C++11)
checks if a type is a union type
(class template) [edit]
(C++11)
checks if a type is a non-union class type
(class template) [edit]
checks if a type is a function type
(class template) [edit]
checks if a type is a pointer type
(class template) [edit]
checks if a type is an lvalue reference
(class template) [edit]
checks if a type is an rvalue reference
(class template) [edit]
checks if a type is a non-static member object pointer
(class template) [edit]
checks if a type is a non-static member function pointer
(class template) [edit]
Composite type categories
checks if a type is a fundamental type
(class template) [edit]
checks if a type is an arithmetic type
(class template) [edit]
(C++11)
checks if a type is a scalar type
(class template) [edit]
(C++11)
checks if a type is an object type
(class template) [edit]
checks if a type is a compound type
(class template) [edit]
checks if a type is either an lvalue reference or rvalue reference
(class template) [edit]
checks if a type is a pointer to a non-static member function or object
(class template) [edit]
Type properties
(C++11)
checks if a type is const-qualified
(class template) [edit]
checks if a type is volatile-qualified
(class template) [edit]
checks if a type is trivial
(class template) [edit]
checks if a type is trivially copyable
(class template) [edit]
checks if a type is a standard-layout type
(class template) [edit]
(C++11)(deprecated in C++20)
checks if a type is a plain-old data (POD) type
(class template) [edit]
(C++11)(deprecated in C++17)(removed in C++20)
checks if a type is a literal type
(class template) [edit]
checks if every bit in the type's object representation contributes to its value
(class template) [edit]
(C++11)
checks if a type is a class (but not union) type and has no non-static data members
(class template) [edit]
checks if a type is a polymorphic class type
(class template) [edit]
checks if a type is an abstract class type
(class template) [edit]
(C++14)
checks if a type is a final class type
(class template) [edit]
checks if a type is an aggregate type
(class template) [edit]
(C++11)
checks if a type is a signed arithmetic type
(class template) [edit]
checks if a type is an unsigned arithmetic type
(class template) [edit]
Supported operations
checks if a type has a constructor for specific arguments
(class template) [edit]
checks if a type has a default constructor
(class template) [edit]
checks if a type has a copy constructor
(class template) [edit]
checks if a type can be constructed from an rvalue reference
(class template) [edit]
checks if a type has an assignment operator for a specific argument
(class template) [edit]
checks if a type has a copy assignment operator
(class template) [edit]
checks if a type has a move assignment operator
(class template) [edit]
checks if a type has a non-deleted destructor
(class template) [edit]
checks if a type has a virtual destructor
(class template) [edit]
checks if objects of a type can be swapped with objects of same or different type
(class template) [edit]
Property queries
obtains the type's alignment requirements
(class template) [edit]
(C++11)
obtains the number of dimensions of an array type
(class template) [edit]
(C++11)
obtains the size of an array type along a specified dimension
(class template) [edit]
Type relationships
(C++11)
checks if two types are the same
(class template) [edit]
checks if a type is a base of the other type
(class template) [edit]
checks if a type can be converted to the other type
(class template) [edit]
checks if a type can be invoked (as if by std::invoke) with the given argument types
(class template) [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
removes const and/or volatile specifiers from the given type
(class template) [edit]
(C++11)(C++11)(C++11)
adds const and/or volatile specifiers to the given type
(class template) [edit]
References
removes a reference from the given type
(class template) [edit]
adds an lvalue or rvalue reference to the given type
(class template) [edit]
Pointers
removes a pointer from the given type
(class template) [edit]
adds a pointer to the given type
(class template) [edit]
Sign modifiers
obtains the corresponding signed type for the given integral type
(class template) [edit]
obtains the corresponding signed type for the given integral type
(class template) [edit]
Arrays
removes one extent from the given array type
(class template) [edit]
removes all extents from the given array type
(class template) [edit]

Miscellaneous transformations

Defined in header <type_traits>
(C++11)(deprecated in C++23)
defines the type suitable for use as uninitialized storage for types of given size
(class template) [edit]
(C++11)(deprecated in C++23)
defines the type suitable for use as uninitialized storage for all given types
(class template) [edit]
(C++11)
applies type transformations as when passing a function argument by value
(class template) [edit]
combines std::remove_cv and std::remove_reference
(class template) [edit]
(C++11)
conditionally removes a function overload or template specialization from overload resolution
(class template) [edit]
chooses one type or another based on compile-time boolean
(class template) [edit]
determines the common type of a group of types
(class template) [edit]
obtains the underlying integer type for a given enumeration type
(class template) [edit]
(C++11)(removed in C++20)(C++17)
deduces the result type of invoking a callable object with a set of arguments
(class template) [edit]
(C++17)
void variadic alias template
(alias template)[edit]

Operations on traits

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

Helper classes

Defined in header <type_traits>
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>

Endian (since C++20)

Defined in header <type_traits>
Type Definition
(C++20)
indicates the endianness of scalar types
(enum) [edit]

See also

C documentation for Type support library