The TR1 library provides 53 class templates that enable compile time evaluations on the properties of types. Such properties are evaluated by means of types traits that represent building blocks for writing overloaded functions or template class specializations.
#include <tr1/type_traits> template <class Ty, Ty val> struct integral_constant { static const Ty value = val; typedef integral_constant<Ty, val> type; typedef integral_constant<bool, false> false_type; typedef integral_constant<bool, true> true_type;
The type traits class templates fall into three main categories: - type predicates, derived from false_type or true_type in accordance with the result of test.
- type queries, derived from integral_constant and providing the numeric value of the property evaluated.
- type transformations, that provide a new nested type in accordance with the transformation applied.
Primary Type CategoriesThe class templates that belong to this category are type predicates.
template <class Ty> struct is_void;
- derived from true_type if Ty is a cv-qualified form of void.
template <class Ty> struct is_integral;
- derived from true_type if Ty is bool, char, unsigned char, signed char, short, unsigned short, int, unsigned int, long and unsigned long; wchar_t, long long and unsigned long long if supported.
template <class Ty> struct is_floating_point;
- derived from true_type if Ty is a cv-qualified form of floating-point type: float, double and long double.
template <class Ty> struct is_array;
- derived from true_type if Ty is a cv-qualified form of an array type [C-array not a tr1::array class].
template <class Ty> struct is_pointer;
- derived from true_type if Ty is a cv-qualified form of ordinary pointer type.
template <class Ty> struct is_reference;
- derived from true_type if Ty is a cv-qualified form of reference type.
template <class Ty> struct is_member_object_pointer;
- derived from true_type if Ty is a cv-qualified form of pointer to data member type.
template <class Ty> struct is_member_function_pointer;
- derived from true_type if Ty is a cv-qualified form of pointer to member function type.
template <class Ty> struct is_enum;
- derived from true_type if Ty is a cv-qualified form of enumeration type.
template <class Ty> struct is_union;
- derived from true_type if Ty is a cv-qualified form of union type. (this may be defined as struct is_union {})
template <class Ty> struct is_class;
- derived from true_type if Ty is a cv-qualified form of class type. (this may be defined as struct is_class {})
template <class Ty> struct is_function;
- derived from true_type if Ty is a cv-qualified form of function type.
Composite Type Categories
template <class Ty> struct is_arithmetic;
- derived from true_type if Ty is a cv-qualified form of arithmetic type: integral type or floating-point type;
template <class Ty> struct is_fundamental;
- derived from true_type if Ty is a cv-qualified form of fundamental type: integral type, floating-point type or void type;
template <class Ty> struct is_object;
- derived from true_type if Ty is a cv-qualified form of object type: not a function type, not a reference type and not void;
template <class Ty> struct is_scalar;
- derived from true_type if Ty is a cv-qualified form of scalar type: arithmetic type, an enumeration type, a pointer type or a pointer to member type;
template <class Ty> struct is_compound;
- derived from true_type if Ty is a cv-qualified form of compound type: not a fundamental type;
template <class Ty> struct is_member_pointer;
- derived from true_type if Ty is a cv-qualified form of pointer to member: pointer to member function or pointer to member data;
template <class Ty> struct is_const;
- derived from true_type if Ty has const qualifier.
template <class Ty> struct is_volatile;
- derived from true_type if Ty has volatile qualifier.
template <class Ty> struct is_pod;
- derived from true_type if Ty is a POD type. POD is any type whose bit representation determines its value. A POD type can be copied with memcpy(). The following assertion shall be true:
is_pod<Ty>::value >= ( is_scalar<Ty>::value || is_void<Ty>::value)
is_pod<Ty>::value == is_pod<const Ty>::value
is_pod<Ty>::value == is_pod<volatile Ty>::value
is_pod<Ty>::value == is_pod<remove_extent<Ty>::type>::value
template <class Ty> struct is_empty;
- derived from true_type if Ty is an empty type.
template <class Ty> struct is_polymorphic;
- derived from true_type if Ty is a polymorphic type. A polymorphic type is a class with at least one virtual function. An implementation may define this template as:
template <typename Ty> struct is_polymorphic {};
template <class Ty> struct is_abstract;
- derived from true_type if Ty is an abstract type. An abstract type is a class with at least one pure virtual function. An implementation may define this template as:
template <typename Ty> struct is_abstract {};
template <class Ty> struct has_trivial_constructor;
- derived from true_type if Ty has a trivial default constructor. A trivial default constructor is an implicitly declared default constructor for a class that:
- has no virtual functions and no virtual base classes
- whose direct base classes have trivial default constructors
- whose non-static data member of class type have trivial default constructors
Classes with trivial default constructors don't require initialization.
Classes that do not have trivial default constructors can't be used as member of unions.
- The following assertion shall be true:
has_trivial_constructor<Ty>::value >= is_pod<Ty>::value
has_trivial_constructor<Ty>::value == has_trivial_constructor<remove_extent<Ty>::value>::value
template <class Ty> struct has_trivial_copy;
- derived from true_type if Ty has a trivial copy constructor.A trivial copy constructor is an implicitly declared copy constructor for a class that:
- has no virtual functions and no virtual base classes
- whose direct base classes have trivial copy constructors
- whose non-static data member of class type have trivial copy constructors
Classes that have trivial copy constructors can be copy-constructed by means of memcpy (optimization).
Classes that do not have trivial copy constructors cannot be used as member of unions.
- The following assertion shall be true:
has_trivial_copy<Ty>::value >= is_pod<Ty>::value
has_trivial_copy<Ty>::value == has_trivial_copy<remove_extent<Ty>::value>::value
template <class Ty> struct has_trivial_assign;
- derived from true_type if Ty has a trivial copy assignment operator. A trivial copy assignment operator is an implicitly declared assignment operator for a class that:
- has no virtual functions and no virtual base classes
- whose direct base classes have trivial copy constructors
- whose non-static data member of class type have trivial copy constructors
Classes that have trivial copy assignment operator can be copied by means of memcpy (optimization).
Classes that do not have trivial copy assignment operator cannot be used as member of unions.
- The following assertion shall be true:
has_trivial_assign<Ty>::value >= is_pod<Ty>::value
has_trivial_assign<Ty>::value == has_trivial_assign<remove_extent<Ty>::value>::value
template <class Ty> struct has_trivial_destructor;
- derived from true_type if Ty has a trivial destructor. A trivial destructor is implicitly declared for a class:
- whose direct base classes have trivial destructors
- whose non-static data member of class type have trivial destructors
Classes that have trivial destructor do not need to be destroyed.
Classes that do not have trivial destructor cannot be used as member of unions.
- The following assertion shall be true:
has_trivial_destructor<Ty>::value >= is_pod<Ty>::value
has_trivial_destructor<Ty>::value == has_trivial_destructor<remove_extent<Ty>::value>::value
template <class Ty> struct has_nothrow_constructor;
- derived from true_type if the default constructor of Ty has a nothrow specifier or if the compiler can determine that it will not throw an exception.
template <class Ty> struct has_nothrow_copy;
- derived from true_type if the copy constructor of Ty has a nothrow specifier or if the compiler can determine that it will not throw an exception.
template <class Ty> struct has_nothrow_assign;
- derived from true_type if the assignment operator of Ty has a nothrow specifier or if the compiler can determine that it will not throw an exception.
template <class Ty> struct has_virtual_destructor;
- derived from true_type if the destructor of Ty is virtual.
template <class Ty> struct is_signed;
- derived from true_type if Ty is a signed integral type.
template <class Ty> struct is_unsigned;
- derived from true_type if Ty is an unsigned integral type.
template <class Ty> struct rank;
- derived from integral_constant<std::size_t, Rank> where Rank is the number of dimensions of the array type Ty, or 0 if Ty is not an array.
rank<int>::value -> 0 (not an array)
rank<int[10]>::value -> 1
rank<int[10][10]>::value -> 2
template <class Ty, unsigned Idx = 0> struct extent;
- derived from integral_constant<std::size_t, Dim> where Dim is the dimension of the Idx th bound of the type Ty.
extent<int,N>::value = 0 (for all N)
extent<int[],0>::value = 0
extent<int[2],N>::value = 2 (N == 0), else 0
extent<int[][3],N>::value = 0 (N == 0), 3 (N == 1), else 0
template <class Ty1, class Ty2> struct is_same;
- derived from true_type if Ty1 and Ty2 are the same type.
template <class From, class To> struct is_convertible;
- derived from true_type if there is a publicly accessible conversion from the type From to the type To.
template <class Base, class Derived> struct is_base_of;
- derived from true_type if Base is the same type of Derived, or if the type Base is a base class of Derived.
template <class Ty> struct remove_const;
- return the type Ty with any const qualifier removed.
template <class Ty> struct remove_volatile;
- return the type Ty with any volatile qualifier removed.
template <class Ty> struct remove_cv;
- return the type Ty with any const and volatile qualifiers removed.
template <class Ty> struct add_const;
- return the type Ty with a top-level const qualifier.
template <class Ty> struct add_volatile;
- return the type Ty with a top-level volatile qualifier.
template <class Ty> struct add_cv;
- return the type Ty with a top-level const and volatile qualifiers.
Equivalent to add_volatile<add_const<Ty>::type>::type
template <class Ty> struct remove_reference;
- return the type Ty1 if the type Ty is Ty1 &, Ty otherwise.
template <class Ty> struct add_reference;
- return the type Ty& if Ty is not a reference type, Ty otherwise.
template <class Ty> struct remove_pointer;
- return the type Ty1 if the type Ty is Ty1 *, Ty otherwise.
template <class Ty> struct add_pointer;
- return the type Ty* if Ty is not a pointer type, Ty otherwise.
template <class Ty> struct remove_extent;
- return the type Ty1 if the type Ty is Ty1[N], Ty otherwise.
example: remove_extent<int>::type => int remove_extent<int[]>::type => int remove_extent<int[2]>::type => int remove_extent<int[][3]>::type => int[3]
template <class Ty> struct remove_all_extents;
- return the type Ty1 if the type Ty is Ty1[M]...[N], Ty otherwise.
example: remove_all_extent<int>::type => int remove_all_extent<int[]>::type => int remove_all_extent<int[2]>::type => int remove_all_extent<int[][3]>::type => int
|
|