This subclause contains templates that may be used to query properties of types at compile time.
Template | Value |
template <class T> struct alignment_of; |
alignof(T). Requires: alignof(T) shall be a valid expression ([expr.alignof]) |
template <class T> struct rank; | If T names an array type, an integer value representing the number of dimensions of T; otherwise, 0. |
template <class T, unsigned I = 0> struct extent; | If T is not an array type, or if it has rank less than or equal to I, or if I is 0 and T has type “array of unknown bound of U”, then 0; otherwise, the bound ([dcl.array]) of the I'th dimension of T, where indexing of I is zero-based |
Each of these templates shall be a UnaryTypeTrait with a base characteristic of integral_constant<size_t, Value>.
[ Example:
// the following assertions hold:
assert(rank_v<int> == 0);
assert(rank_v<int[2]> == 1);
assert(rank_v<int[][4]> == 2);
— end example ]
[ Example:
// the following assertions hold:
assert(extent_v<int> == 0);
assert(extent_v<int[2]> == 2);
assert(extent_v<int[2][4]> == 2);
assert(extent_v<int[][4]> == 0);
assert((extent_v<int, 1>) == 0);
assert((extent_v<int[2], 1>) == 0);
assert((extent_v<int[2][4], 1>) == 4);
assert((extent_v<int[][4], 1>) == 4);
— end example ]