On this page
7.9 Type Traits ¶
The C++ front end implements syntactic extensions that allow compile-time determination of various characteristics of a type (or of a pair of types).
-
__has_nothrow_assign (type) -
If
typeisconst-qualified or is a reference type then the trait isfalse. Otherwise if__has_trivial_assign (type)istruethen the trait istrue, else iftypeis a cv-qualified class or union type with copy assignment operators that are known not to throw an exception then the trait istrue, else it isfalse. Requires:typeshall be a complete type, (possibly cv-qualified)void, or an array of unknown bound. -
__has_nothrow_copy (type) -
If
__has_trivial_copy (type)istruethen the trait istrue, else iftypeis a cv-qualified class or union type with copy constructors that are known not to throw an exception then the trait istrue, else it isfalse. Requires:typeshall be a complete type, (possibly cv-qualified)void, or an array of unknown bound. -
__has_nothrow_constructor (type) -
If
__has_trivial_constructor (type)istruethen the trait istrue, else iftypeis a cv class or union type (or array thereof) with a default constructor that is known not to throw an exception then the trait istrue, else it isfalse. Requires:typeshall be a complete type, (possibly cv-qualified)void, or an array of unknown bound. -
__has_trivial_assign (type) -
If
typeisconst- qualified or is a reference type then the trait isfalse. Otherwise if__is_pod (type)istruethen the trait istrue, else iftypeis a cv-qualified class or union type with a trivial copy assignment ([class.copy]) then the trait istrue, else it isfalse. Requires:typeshall be a complete type, (possibly cv-qualified)void, or an array of unknown bound. -
__has_trivial_copy (type) -
If
__is_pod (type)istrueortypeis a reference type then the trait istrue, else iftypeis a cv class or union type with a trivial copy constructor ([class.copy]) then the trait istrue, else it isfalse. Requires:typeshall be a complete type, (possibly cv-qualified)void, or an array of unknown bound. -
__has_trivial_constructor (type) -
If
__is_pod (type)istruethen the trait istrue, else iftypeis a cv-qualified class or union type (or array thereof) with a trivial default constructor ([class.ctor]) then the trait istrue, else it isfalse. Requires:typeshall be a complete type, (possibly cv-qualified)void, or an array of unknown bound. -
__has_trivial_destructor (type) -
If
__is_pod (type)istrueortypeis a reference type then the trait istrue, else iftypeis a cv class or union type (or array thereof) with a trivial destructor ([class.dtor]) then the trait istrue, else it isfalse. Requires:typeshall be a complete type, (possibly cv-qualified)void, or an array of unknown bound. -
__has_virtual_destructor (type) -
If
typeis a class type with a virtual destructor ([class.dtor]) then the trait istrue, else it isfalse. Requires:typeshall be a complete type, (possibly cv-qualified)void, or an array of unknown bound. -
__is_abstract (type) -
If
typeis an abstract class ([class.abstract]) then the trait istrue, else it isfalse. Requires:typeshall be a complete type, (possibly cv-qualified)void, or an array of unknown bound. -
__is_base_of (base_type, derived_type) -
If
base_typeis a base class ofderived_type([class.derived]) then the trait istrue, otherwise it isfalse. Top-level cv-qualifications ofbase_typeandderived_typeare ignored. For the purposes of this trait, a class type is considered is own base. Requires: if__is_class (base_type)and__is_class (derived_type)aretrueandbase_typeandderived_typeare not the same type (disregarding cv-qualifiers),derived_typeshall be a complete type. A diagnostic is produced if this requirement is not met. -
__is_class (type) -
If
typeis a cv-qualified class type, and not a union type ([basic.compound]) the trait istrue, else it isfalse. -
__is_empty (type) -
If
__is_class (type)isfalsethen the trait isfalse. Otherwisetypeis considered empty if and only if:typehas no non-static data members, or all non-static data members, if any, are bit-fields of length 0, andtypehas no virtual members, andtypehas no virtual base classes, andtypehas no base classesbase_typefor which__is_empty (base_type)isfalse. Requires:typeshall be a complete type, (possibly cv-qualified)void, or an array of unknown bound. -
__is_enum (type) -
If
typeis a cv enumeration type ([basic.compound]) the trait istrue, else it isfalse. -
__is_literal_type (type) -
If
typeis a literal type ([basic.types]) the trait istrue, else it isfalse. Requires:typeshall be a complete type, (possibly cv-qualified)void, or an array of unknown bound. -
__is_pod (type) -
If
typeis a cv POD type ([basic.types]) then the trait istrue, else it isfalse. Requires:typeshall be a complete type, (possibly cv-qualified)void, or an array of unknown bound. -
__is_polymorphic (type) -
If
typeis a polymorphic class ([class.virtual]) then the trait istrue, else it isfalse. Requires:typeshall be a complete type, (possibly cv-qualified)void, or an array of unknown bound. -
__is_standard_layout (type) -
If
typeis a standard-layout type ([basic.types]) the trait istrue, else it isfalse. Requires:typeshall be a complete type, (possibly cv-qualified)void, or an array of unknown bound. -
__is_trivial (type) -
If
typeis a trivial type ([basic.types]) the trait istrue, else it isfalse. Requires:typeshall be a complete type, (possibly cv-qualified)void, or an array of unknown bound. -
__is_union (type) -
If
typeis a cv union type ([basic.compound]) the trait istrue, else it isfalse. -
__underlying_type (type) -
The underlying type of
type. Requires:typeshall be an enumeration type ([dcl.enum]). -
__integer_pack (length) -
When used as the pattern of a pack expansion within a template definition, expands to a template argument pack containing integers from
0tolength-1. This is provided for efficient implementation ofstd::make_integer_sequence.
© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
https://gcc.gnu.org/onlinedocs/gcc-10.5.0/gcc/Type-Traits.html