Include the TR1 header <type_traits> to define several templates that provide compile-time constants giving information about the properties of their type arguments.
namespace std {
namespace tr1 {
// HELPER CLASSES
template <class Ty, Ty v>
struct integral_constant;
typedef integral_constant<bool, false> false_type;
typedef integral_constant<bool, true> true_type;
// TYPE CATEGORIES
template <class Ty> struct is_void;
template <class Ty> struct is_integral;
template <class Ty> struct is_floating_point;
template <class Ty> struct is_array;
template <class Ty> struct is_pointer;
template <class Ty> struct is_reference;
template <class Ty> struct is_member_object_pointer;
template <class Ty> struct is_member_function_pointer;
template <class Ty> struct is_enum;
template <class Ty> struct is_union;
template <class Ty> struct is_class;
template <class Ty> struct is_function;
template <class Ty> struct is_arithmetic;
template <class Ty> struct is_fundamental;
template <class Ty> struct is_object;
template <class Ty> struct is_scalar;
template <class Ty> struct is_compound;
template <class Ty> struct is_member_pointer;
// TYPE PROPERTIES
template <class Ty> struct is_const;
template <class Ty> struct is_volatile;
template <class Ty> struct is_pod;
template <class Ty> struct is_empty;
template <class Ty> struct is_polymorphic;
template <class Ty> struct is_abstract;
template <class Ty> struct has_trivial_constructor;
template <class Ty> struct has_trivial_copy;
template <class Ty> struct has_trivial_assign;
template <class Ty> struct has_trivial_destructor;
template <class Ty> struct has_nothrow_constructor;
template <class Ty> struct has_nothrow_copy;
template <class Ty> struct has_nothrow_assign;
template <class Ty> struct has_virtual_destructor;
template <class Ty> struct is_signed;
template <class Ty> struct is_unsigned;
template <class Ty> struct alignment_of;
template <class Ty> struct rank;
template <class Ty, unsigned _I = 0> struct extent;
// TYPE COMPARISONS
template <class Ty1, class Ty2> struct is_same;
template <class From, class To> struct is_convertible;
template <class Base, class Derived> struct is_base_of;
// CONST-VOLATILE MODIFICATIONS
template <class Ty> struct remove_const;
template <class Ty> struct remove_volatile;
template <class Ty> struct remove_cv;
template <class Ty> struct add_const;
template <class Ty> struct add_volatile;
template <class Ty> struct add_cv;
// REFERENCE MODIFICATIONS
template <class Ty> struct remove_reference;
template <class Ty> struct add_reference;
// ARRAY MODIFICATIONS
template <class Ty> struct remove_extent;
template <class Ty> struct remove_all_extents;
// POINTER MODIFICATIONS
template <class Ty> struct remove_pointer;
template <class Ty> struct add_pointer;
//OTHER MODIFICATIONS
template <class Ty> struct aligned_storage;
} // namespace tr1
} // namespace std
With XL C++, these traits behave as specified in the following section.
template <typename T> struct is_class{};
template <typename T> struct is_union{};
The type traits for which this latitude is granted are:
XL C++ does not take advantage of this latitude. Full implementations of these type traits are provided
The template class, when specialized with an integral type and a value of that type, represents an object that holds a constant of that integral type with the specified value.
template <class Ty, Ty v>
struct integral_constant {
static const Ty value = v;
typedef Ty value_type;
typedef integral_constant<Ty, v> type;
};
typedef integral_constant<bool, true> true_type;
typedef integral_constant<bool, false> false_type;
typedef integral_constant<bool, false> false_type;
The type is a synonym for a specialization of the template integral_constant.
typedef integral_constant<bool, true> true_type;
The type is a synonym for a specialization of the template integral_constant.
Unary Type Traits describe a property of a single type. Every Unary Type Trait possesses a static data member named value. For most traits, this member has type bool, and indicates the presence or absence of a specific property or trait of the argument type. For example, the value of the following expression will be true if the type argument Ty is a union type, and false otherwise:
std::tr1::is_union<Ty>::value
A few of the Unary Type Traits possess a static data member named value whose type is not bool. An example is the type trait extent, which gives the number of elements in an array type:
typedef char arr[42]; size_t sz = std::tr1::extent<arr>::value; //sz == 42;
Every instance of a Unary Type Trait is derived from an instance of integral_constant. All Unary Type Traits are default-constructible.
A given type Ty will satisfy one of the following categories.
template <class Ty>
struct is_void;
An instance of the type predicate holds true if the type Ty is void or a cv-qualified form of void, otherwise it holds false.
template <class Ty>
struct is_integral;
An instance of the type predicate holds true if the type Ty is one of the integral types, or a cv-qualified form of one of the integral types, otherwise it holds false.
An integral type is one of bool, char, unsigned char, signed char, wchar_t, short, unsigned short, int, unsigned int, long, and unsigned long. In addition, with compilers that provide them, an integral type can be one of long long, unsigned long long, __int64, and unsigned __int64.
template <class Ty>
struct is_floating_point;
An instance of the type predicate holds true if the type Ty is a floating point type or a cv-qualified form of a floating point type, otherwise it holds false.
A floating point type is one of float, double, or long double.
template <class Ty>
struct is_array;
An instance of the type predicate holds true if the type Ty is an array type, otherwise it holds false.
template <class Ty>
struct is_pointer;
An instance of the type predicate holds true if the type Ty is a pointer to void, a pointer to an object, or a pointer to a function, or a cv-qualified form of one of them, otherwise it holds false. Note that is_pointer holds false if Ty is a pointer to member or a pointer to member function.
template <class Ty>
struct is_reference;
An instance of the type predicate holds true if the type Ty is a reference to an object or to a function, otherwise it holds false.
template <class Ty>
struct is_member_object_pointer;
An instance of the type predicate holds true if the type Ty is a pointer to member object or a cv-qualified pointer to member object, otherwise it holds false. Note that is_member_object_pointer holds false if Ty is a pointer to member function.
template <class Ty>
struct is_member_function_pointer;
An instance of the type predicate holds true if the type Ty is a pointer to member function or a cv-qualified pointer to member function, otherwise it holds false.
template <class Ty>
struct is_enum;
An instance of the type predicate holds true if the type Ty is an enumeration type or a cv-qualified form of an enumeration type, otherwise it holds false.
template <class Ty>
struct is_union;
An instance of the type predicate holds true if the type Ty is a union type or a cv-qualified form of a union type, otherwise it holds false.
template <class Ty>
struct is_class;
An instance of the type predicate holds true if the type Ty is a type defined as a class or a struct, or a cv-qualified form of one of them, otherwise it holds false.
template <class Ty>
struct is_function;
An instance of the type predicate holds true if the type Ty is a function type, otherwise it holds false.
template <class Ty>
struct is_arithmetic;
An instance of the type predicate holds true if the type Ty is an arithmetic type, that is, an integral type or a floating point type, or a cv-qualified form of one of them, otherwise it holds false.
template <class Ty>
struct is_fundamental;
An instance of the type predicate holds true if the type Ty is a fundamental type, that is, void, an integral type, an floating point type, or a cv-qualified form of one of them, otherwise it holds false.
template <class Ty>
struct is_object;
An instance of the type predicate holds false if the type Ty is a reference type, a function type, or void, or a cv-qualified form of one of them, otherwise holds true.
template <class Ty>
struct is_scalar;
An instance of the type predicate holds true if the type Ty is an integral type, a floating point type, an enumeration type, a pointer type, or a pointer to member type, or a cv-qualified form of one of them, otherwise it holds false.
template <class Ty>
struct is_compound;
An instance of the type predicate holds false if the type Ty is a scalar type (that is, if is_scalar<Ty> holds true), otherwise it holds true. Thus, the predicate holds true if Ty is an array type, a function type, a pointer to void or an object or a function, a reference, a class, a union, an enumeration, or a pointer to non-static class member, or a cv-qualified form of one of them.
template <class Ty>
struct is_member_pointer;
An instance of the type predicate holds true if the type Ty is a pointer to member function or a pointer to member object, or a cv-qualified form of one of them, otherwise it holds false.
template <class Ty>
struct is_const;
An instance of the type predicate holds true if Ty is const-qualified.
template <class Ty>
struct is_volatile;
An instance of the type predicate holds true if Ty is volatile-qualified.
template <class Ty>
struct is_pod;
An instance of the type predicate holds true if the type Ty is a scalar type, a POD aggregate type, or a cv-qualified form of one of them, or an array of such a type, otherwise it holds false.
A POD aggregate type is a class, struct, or union whose non-static data members are all scalar types or POD aggregates, and that has no references, no user-defined copy assignment operator, and no user-defined destructor.
template <class Ty>
struct is_empty;
An instance of the type predicate holds true if the type Ty is an empty class, otherwise it holds false.
template <class Ty>
struct is_polymorphic;
An instance of the type predicate holds true if the type Ty is a class that declares or inherits a virtual function, otherwise it holds false.
template <class Ty>
struct is_abstract;
An instance of the type predicate holds true if the type Ty is a class that has at least one pure virtual function, otherwise it holds false.
template <class Ty>
struct has_trivial_constructor;
An instance of the type predicate holds true if the type Ty is a class that has a trivial constructor, otherwise it holds false.
A constructor for a class Ty is trivial if:
template <class _T> struct has_trivial_assign;
An instance of the type predicate holds true if the type Ty is a class that has a trivial copy constructor, otherwise it holds false.
A copy constructor for a class Ty is trivial if:
template <class Ty>
struct has_trivial_destructor;
An instance of the type predicate holds true if the type Ty is a class that has a trivial destructor, otherwise it holds false.
A destructor for a class Ty is trivial if:
template <class Ty>
struct has_nothrow_constructor;
An instance of the type predicate holds true if the type Ty has a nothrow default constructor, otherwise it holds false.
template <class Ty>
struct has_nothrow_copy;
An instance of the type predicate holds true if the type Ty has a nothrow copy constructor, otherwise it holds false.
template <class Ty>
struct has_nothrow_assign;
An instance of the type predicate holds true if the type Ty has a nothrow copy assignment operator, otherwise it holds false.
A nothrow function is a function that has an empty throw specifier, or a function which the compiler can otherwise determine will not throw an exception.
template <class Ty>
struct has_virtual_destructor;
An instance of the type predicate holds true if the type Ty is a class that has a virtual destructor, otherwise it holds false.
template <class _Ty>
struct is_signed;
An instance of the type predicate holds true if the type Ty is a signed integral type or a cv-qualified signed integral type, otherwise it holds false.
template <class Ty>
struct is_unsigned;
An instance of the type predicate holds true if the type Ty is an unsigned integral type or a cv-qualified unsigned integral type, otherwise it holds false.
template <class Ty>
struct alignment_of;
The type query holds the value of the alignment of the type Ty.
template <class Ty>
struct rank;
The type query holds the value of the number of dimensions of the array type Ty, or 0 if Ty is not an array type.
template <class _Ty, unsigned _I = 0> struct extent;
The type query holds the value of the number of elements in the Ith bound of objects of type Ty. If Ty is not an array type or its rank is less than I, or if I is zero and Ty is of type "array of unknown bound of U", it holds the value 0.
Binary Type Traits provide information about a relationship between two types. Every Binary Type Trait possesses a static data member of type bool named value. This member indicates the presence or absence of a specific relationship between the two argument types. For example, the value of the following expression will be true if the type arguments Ty1 and Ty2 are the same type, and false otherwise:
std::tr1::is_same<Ty1, Ty2>::value
template <class Ty, class Ty2>
struct is_same;
An instance of the type predicate holds true if the types Ty1 and Ty2 are the same type, otherwise it holds false.
template <class From, class To>
struct is_convertible;
An instance of the type predicate holds true if the expression To to = from;, where from is an object of type From, is well-formed.
template <class Base, class Derived>
struct is_base_of;
An instance of the type predicate holds true if the type Base is a base class of the type Derived, otherwise it holds false.
Transformation Type Traits modify a type. Every Transformation Type Trait possesses a nested typedef named type that represents the result of the modification. For example, for a given type Ty, the type std::tr1::add_reference<Ty>::type is equivalent to the type Ty &.
template <class Ty>
struct remove_const;
An instance of the type modifier holds a modified-type that is Ty1 when Ty is of the form const Ty1, otherwise Ty.
template <class Ty>
struct remove_volatile;
An instance of the type modifier holds a modified-type that is Ty1 when Ty is of the form volatile Ty1, otherwise Ty.
template <class Ty>
struct remove_cv;
An instance of the type modifier holds a modified-type that is Ty1 when Ty is of the form const Ty1, volatile Ty1, or const volatile Ty1, otherwise Ty.
template <class Ty>
struct add_const;
An instance of the type modifier holds a modified-type that is Ty if Ty is a reference, a function, or a const-qualified type, otherwise const Ty.
template <class Ty>
struct add_volatile;
An instance of the type modifier holds a modified-type that is Ty if Ty is a reference, a function, or a volatile-qualified type, otherwise volatile volatile Ty.
template <class Ty>
struct add_cv;
An instance of the type modifier holds the modified-type add_volatile< add_const<Ty> >.
template <class Ty>
struct remove_reference;
An instance of the type modifier holds a modified-type that is Ty1 when Ty is of the form Ty1&, otherwise Ty.
template <class Ty>
struct add_reference;
An instance of the type modifier holds a modified-type that is Ty if Ty is a reference, otherwise Ty&.
template <class Ty>
struct remove_pointer;
An instance of the type modifier holds a modified-type that is Ty1 when Ty is of the form Ty1*, Ty1* const, Ty1* volatile, or Ty1* const volatile, otherwise Ty.
template <class Ty>
struct add_pointer;
An instance of the type modifier holds the modified-type Ty1* if Ty is of the form Ty1[N]or Ty1&, otherwise Ty*.
template <class Ty>
struct remove_extent;
An instance of the type modifier holds a modified-type that is Ty1 when Ty is of the formTy1[N], otherwise Ty.
template <class Ty>
struct remove_all_extents;
An instance of the type modifier holds a modified-type that is the element type of the array type Ty with all array dimensions removed, or Ty if Ty is not an array type.
template <std::size_t _Len, std::size_t _Align>
struct aligned_storage {
typedef aligned-type type;
};
The nested typedef type is a synonym for a POD type with alignment Align and size Len. Align must be equal to alignment_of<Ty1>::valuefor some type Ty1.
Certain materials included or referred to in this document are copyright P.J. Plauger and/or Dinkumware, Ltd. or are based on materials that are copyright P.J. Plauger and/or Dinkumware, Ltd.
Notwithstanding the meta-data for this document, copyright information for this document is as follows:
Copyright © IBM Corp. 1999, 2010. & Copyright © P.J. Plauger and/or Dinkumware, Ltd. 1992-2006.