RAD Studio
ContentsIndex
PreviousUpNext
Type Trait Functions (C++0x)

This section contains Type Trait Functions help topics.

Name 
Description 
C++Builder 2009 supports a library of type trait functions designed to support compile time metaprogramming techniques.
These type trait functions are intrinsic type functions that are defined in a manner similar to typeid, sizeof, and decltype. The type trait functions accept a type at compile time and deliver a compile time constant expression as a result, typically of type bool.
Each type trait function is named after its respective type trait, prefixed with a double underscore (__), which marks a name reserved to the implementation.
For example, the following is a type trait function that evaluates... more 
Category
Type Trait Functions
Syntax:
unsigned int __alignment_of( typename T )
This function is not necessary, as alignof is a proposed new keyword. 
Category
Type Trait Functions
Syntax
unsigned int __array_extent( typename T, unsigned intI )
Returns: If T is not an array type, or if it has rank less than I, or if I is 0 and T has type “array of unknown bound of U”, then 0; otherwise, the size of the I’th dimension of T
Category
Type Trait Functions
Syntax
unsigned int __array_rank( typename T )
Returns: If T names an array type, an integer representing the number of dimensions of T; otherwise, 0.. 
Category
Type Trait Functions
Syntax
bool __has_nothrow_assign ( typename T )
Returns true if and only if compiler can prove T has a copy assignment operator that it cannot throw.
True if __has_trivial_assign(T).
Also true if copy assignment operator has an empty exception specification.
Ox interaction false if copy assignment is defined as deleted. 
Category
Type Trait Functions
Syntax
bool __has_nothrow_copy_constructor ( typename T )
Returns true if and only if compiler can prove T has a copy constructor that cannot throw.
Error if T is an incomplete type.
True if __has_trivial_copy_constructor(T).
Ox interaction false if copy constructor is defined as deleted. 
Category
Type Trait Functions
Syntax
bool __has_nothrow_default_constructor (typename T )
Returns true if and only if T can prove T has a default constructor it cannot throw.
Error if T is an incomplete type.
True if __has_trivial_default_constructor(T).
True if default constructor has an empty exception specification.
False (but well-formed) if a class type does not have a default constructor.
False if T is a reference type.
Ox interaction false if the default constructor is defined as deleted. 
Category
Type Trait Functions
Syntax
bool __has_trivial_assign (typename T )
Returns true if and only if T has a trivial copy assignment operator.
Error if T is an incomplete type.
The definition from Section 20.4.4.3 of the Working Draft notes says a type T has a trivial copy assignment operator if T is neither const nor a reference type and T is one of:
  • a scalar type (or array thereof)
  • a class type with a trivial copy assignment operator
According to Section 21.8 p11 of the Working Draft, a copy assignment operator for class X is trivial if:
Category
Type Trait Functions
Syntax
bool __has_trivial_copy_constructor ( typename T )
Returns true if and only if T has a trivial default constructor.
Error if T is an incomplete type.
False (but well-formed) if a class type does not have a default constructor
The definition (from Section 20.4.4.3 of the Working Draft) notes has a type T has a trivial copy constructor if it is in the list::
  • a scalartype (or array thereof)
  • a reference type (or array thereof)
  • an array of class type with trivial destructor
  • a class type with a trivial copy constructor (12.8)
According to Section 12.8... more 
Category
Type Trait Functions
Syntax
bool __has_trivial_default_constructor (typename T )
Returns true if and only if T has a trivial default constructor.
Errorif T is an incomplete type.
False (but well-formed) if a class type does not have a default constructor.
According to the definition from Section 20.4.4.3 of the Working Draft notes, a type T has a trivial copy assignment operator if:
  • a scalar type (or array thereof)
  • an array of class type with a trivial default constructor
  • a class type with a trivial default constructorr
Especially note false for reference types.
According to Section 21.1 p5 of... more 
Category
Type Trait Functions
Syntax
bool __has_trivial_destructor (typename T )
Returns true if and only if T has a trivial destructor.
Errorif T is an incomplete type.
Note: Definition from 20.4.4.3 notes has a type T has a trivial destructor if T is one of:
  • a scalartype (or array thereof)
  • a scalartype (or array thereof)
  • an array of class type with a trivial destructor
  • an array of class type with a trivial destructor
  • a class type with a trivial destructor

According to Section 12.4, p 3 of the Working Draft, a destructor for class X is trivial if:
Category
Type Trait Functions
Syntax
bool __has_virtual_destructor (typename T )
Returns true if and only if T is a class type and the destructor is declared virtual.
Error if T is an incomplete type.
Derived classes have a virtual destructor if the a base class destructor is declared virtual, even if not explicitly declared as virtual in the derived class. 
Category
Type Trait Functions
Syntax
bool __is_abstract( typename T )
Returns true if and only if T is an abstract class type.
Error if T is an incomplete type.
Note: An abstract class is one that contains or inherits (without overriding) at least one pure virtual function, according to Section 10.4 of the Working Draft.
 
Category
Type Trait Functions
Syntax
bool __is_arithmetic ( typename T )
Returns __is_integral(T) || __is_floating_point(T). 
Category
Type Trait Functions
Syntax
bool __is_array( typename T )
Returns true if and only if T is an array type.
Note: False for decayed pointer-to-array and reference to array; true for array-of-unknown bounds.
 
Category
Type Trait Functions
Syntax
bool __is_base_of (typename Base, typename Derived)
Returns true if and only if Base is a base class of Derived.
Error if Derived is an incomplete type and Base is a class-type..
Note: False (but well formed) if either Base or Derived is a union or non-class type, even if the other is an incomplete type.
True if any class in the DAG of base classes for Derived is Base. This includes private, protected, ambiguous or virtual bases so simply return true the first time the search finds a match. 
Category
Type Trait Functions
Syntax
bool __is_class(typename T)
Returns true if and only if T is a class type, and NOT a union type.
Returns true for classes declared with the class key class or struct.
Returns false for reference/pointer to class type.
Returns true for specialization of a class template.
Ill-formed if called with the name of a template, without specifying the template parameters. A template is not a type; it is a type generator. 
Category
Type Trait Functions
Syntax
bool __is_complete_type(T)
Returns True if and only if T is a complete type at the point of the function call.
This is a support function to help users track ill-formed code, not a distinct type trait required by the standard. This function is typically used in static_assert statements, because most other uses risk violating the ODR. Note that void and arrays of unknown bound are always incomplete types. 
Category
Type Trait Functions
Syntax
bool __is_compound( typename T )
Returns true if and only if T is a compound type..
A compound type is essentially one item from the following list:
  • array
  • function
  • pointer
  • pointer-to-member
  • reference
  • class
  • union
  • enumeration
Compound types are defined in Section 3.92 of the Working Draft. 
Category
Type Trait Functions
Syntax
bool __is_const(typename T)
Returns true if and only if T is a const-qualified type.
Note: References are never cv-qualified.
For pointers, refers to the pointer type itself, and NOT the pointed-to type.
Returns true if T is both const and volatile qualified. 
Category
Type Trait Functions
Syntax
bool __is_convertible ( typename From, typename To )
Returns true if and only if From is implicitly convertible to To.
Error if either From or To is an incomplete type.
Note: Exact test described in Working Draft Section 20.4.4.3 is true if the following code is well formed:  
Category
Type Trait Functions
Syntax
bool __is_empty( typename T )
Returns true if and only if T is an 'empty' type.
Error if T is an incomplete type
Definition of __is_empty is given in the table in Section 20.4.4.3 of the Working Draft.
A type T is empty if T:
  • is a class type but not a union type.
  • has no non-static data members other than bit-fields of length 0
  • has no virtual member functions
  • has no virtual base classes
  • has no base class which is not empty.
 
Category
Type Trait Functions
Usage: bool _is_enum ( typename T )
Returns true if and only if T is an enum type.
Returns true for the C++0x strongly typed enums as well.
Returns false for reference/pointer to enum type. 
Category
Type Trait Functions
Syntax
bool __is_floating_point(typename T)
Returns true if and only if T is a (potentially cv-qualified) floating point type.
The standard set of floating point types is:
  • floating
  • double
  • long double

Floating point types are defined in Section 3.9.1 p 7 of the Working Draft. 
Category
Type Trait Functions
Syntax
bool __is_function( typename T )
Returns true if and only if T is a function type.
Returns false for reference/pointer to function type.
Returns true for specialization of a function template.
Ill-formed if called with the name of a template, without specifying the template parameters. A template is not a type; it is a type generator. 
Category
Type Trait Functions
Syntax
bool __is_fundamental( typename T )
Returns true if and only if T is a fundamental type.
Fundamental types are defined in Section 3.9.1 of the Working Draft.
Definition is essentially __is_arithmetic(T) || __is_void(T)
Alternative is a compound type, such as pointer, reference, enum, class or array. 
Category
Type Trait Functions
Syntax
bool __is_integral(typename T)
Returns True if and only if T is an (potentially cv-qualified) integral type.
Integral types are defined in the Working Standard, Section 3.9.1 page 7.
The standard set of integral types is: bool, char, signed char, unsigned char, char16_t, char32_t, wchar_t, [unsigned]short, [unsigned] int, [unsigned] long, and [unsigned] long. 
Category
Type Trait Functions
Syntax
bool __is_lvalue_expr( typename T )
Returns true if and only if T is an lvalue expression. 
Category
Type Trait Functions
Syntax
bool __is_lvalue_reference( typename T )
Returns true if and only if T is an lvalue reference type.
Can be a reference to an object or function type. 
Category
Type Trait Functions
Syntax
bool __is_member_function_pointer( typename T )
Returns true if and only if T is a pointer-to-member-function type .
Returns false for a pointer-to-data member.
Returns false for a regular object pointer. 
Category
Type Trait Functions
Syntax
bool __is_member_object_pointer( typename T )
Returns true if and only if T is a pointer-to-data-member type.
Returns false for pointer-to-member-function.
Returns false for a regular object pointer. 
Category
Type Trait Functions
Syntax
bool __is_member_pointer( typename T )
Returns: __is_member_object_pointer(T) || __is_member_function_pointer(T)
Category
Type Trait Functions
Syntax
bool __is_object( typename T)
Returns true if and only if T is an object type.
Defined in Section 3.9 p8 of the Working Draft, essentially:
!__is_reference(T) && !__is_function(T) && !__is_void(T)
Category
Type Trait Functions
Syntax
bool __is_pod( typename T )
Returns true if and only if T is a POD (plain ol' data) type.
Error if T is an incomplete type.
POD types are defined in Section 3.9 p10 of the Working Draft.
POD classes are defined in Section 9 p9 of the Working Draft.
Effectively __is_trivial_type(T) && is standard_layout(T) 
Category
Type Trait Functions
Syntax
bool __is_pointer( typename T )
Returns true if and only if T is a pointer type.
Can be an object pointer or a function pointer.
False for pointer-to-member. 
Category
Type Trait Functions
Syntax
bool __is_polymorphic( typename T )
Returns true if and only if T is a poiymorphic class type.
Error if T is an incomplete type.
Polymorphic classes are defined in Section 10.3 of the Working Draft.
"A class that declares or inherits a virtual function is called a polymorphic class." 
Category
Type Trait Functions
Syntax
bool __is_reference( typename T )
Returns: __is_lvalue_reference(T) || __is_rvalue_reference(T)
Category
Type Trait Functions
Syntax
bool __is_rvalue_expr( typename T )
Returns true if and only if T is an rvalue expression. 
Category
Type Trait Functions
Usage: bool __is_rvalue_reference( typename T )
Returns true if and only if T is an rvalue reference type.
Can be a reference to an object or function type, even though function type rvalues make little sense beyond metaprogramming in the type system. 
Category
Type Trait Functions
Syntax
bool __is_same( typename T, typename U )
Returns true if and only if T and U are the same type, with identical CV qualifiers.
Names of types when calling __is_same may be different aliases for the same type, if called with typedefs or template type parameters.
Ox interaction: template aliases will allow another way to alias the same type name. 
Category
Type Trait Functions
Syntax
bool __is_scalar( typename T )
Returns true if and only if T is a scalar type.
Scalar type is defined in Section 3.9 p10 of the Working Draft, essentially:
__is_arithmetic( T ) || __is_enumeration(T) ||
__is_pointer(T) || __is_member_pointer(T)
Scalar types have a built in meaning for operator < as well as operator ==. Therefore, __closure is not a scalar type. 
Category
Type Trait Functions
Syntax
_bool __is_signed( typename T )
Returns true if and only if __is_arithmetic(T) and T recognizes values less than zero. 
Category
Type Trait Functions
Syntax
bool __is_standard_layout(typename T)
Returns true if and only if T is a standard layout type.
Error if T is an incomplete type.
Standard layout classes are defined in Section 9, p 6 of the Working Draft.
A standard layout type is:
  • a scalar type
  • an array of standard layout types
  • a standard layout class type:
A standard layout class is a class that has:
  • no non-static data members other than standard layout types
  • same access control for all non-static data members (such as all public or private)
  • no base classes other than standard layout classes... more 
Category
Type Trait Functions
Syntax
bool __is_trivial( typename T )
Returns true if and only if T is a trivial type.
Error if T is an incomplete type.
Trivial types are defined in Section 3.9 p10 of the Working Draft.
Trivial classes are defined in Section 9 p5 of the Working Draft.
Returns true if T is both const and volatile qualified.
A type is trivial if it is:
  • a scalar type
  • an array of trivial types
  • a class/union type where all 4 special members are trivial:
    • default constructor
    • copy constructor
    • copy assignment operator
    • destructor
Consult this online help for... more 
Category
Type Trait Functions
Syntax
bool __is_union( typename T )
Returns true if and only if T is a union type.
Note: unions are class types declared with the class-key union.
Returns false for reference/pointer to union type. 
Category
Type Trait Functions
Syntax
bool __is_unsigned
Returns true if _is_arithmetic(T) and T does not recognize values less than zero 
Category
Type Trait Functions
Syntax
bool __is_void( typename T )
Returns True if T is (potentially cv-qualified) void. Returns False otherwise, including for pointer or reference to void. 
Category
Type Trait Functions
Syntax
bool __is_volatile( typename T )
Returns true if and only if T is a volatile-qualified type..
Note: References are never cv-qualified.
For pointers, refers to the pointer type itself, and NOT the pointed-to type.
Returns true if T is both const and volatile qualified. 
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!