<html>
<head>
<TITLE>
ISO/IEC JTC1/SC22/WG21
N1620
</TITLE>
</head>
<body>
<h1>
<img align=top src="/pics/iso44.gif" alt="ISO/">
<img align=top src="/pics/iec44.gif" alt="IEC">
JTC1/SC22/WG21
N1620
</h1>
<pre>
                                                        <a hRef="../2004/n1620.htm">N1620</a>=04-0060
                                                        Howard Hinnant
                                                        24 Mar 2004

                          Dimension and Rank

Resolution to TR issue 3.9


4.2  Header &lt;type_traits> synopsis:

Add under:

// type properties:
...
template &lt;class T> struct rank;
template &lt;class T, unsigned I = 0> struct extent;

Change:

template &lt;class T> struct remove_dimension;
template &lt;class T> struct remove_all_dimensions;

to:

template &lt;class T> struct remove_extent;
template &lt;class T> struct remove_all_extents;

4.3.4 Type properties

Add:

template &lt;class T> struct rank {
 static const std::size_t value = implementation_defined;
  typedef std::size_t                        value_type;
 typedef integral_constant&lt;value_type,value> type;
 operator type()const;
};

value: An implementation-defined integer value representing the rank
of objects of type T (8.3.4). [Note - the term "rank" here is used to
describe the number of dimensions of an array type - end note]

[example -

 // the following assertions should hold:
assert(rank&lt;int>::value == 0);
assert(rank&lt;int[2]>::value == 1);
assert(rank&lt;int[][4]>::value == 2);

- end example]

...

template &lt;class T, unsigned I = 0> struct extent {
 static const std::size_t value = implementation_defined;
  typedef std::size_t value_type;
 typedef integral_constant&lt;value_type,value> type;
 operator type()const;
};

value: An implementation-defined integer value representing the extent
(dimension) of the I'th bound of objects of type T (8.3.4). If the
type T is not an array type, has rank of less than I, or if I == 0 and
is of type "array of unknown bound of T", then value shall evaluate to
zero; otherwise value shall evaluate to the number of elements in the
I'th array bound of T. [Note - the term "extent" here is used to
describe the number of elements in an array type - end note]

[example -

 // the following assertions should hold:
assert(extent&lt;int>::value == 0);
assert(extent&lt;int[2]>::value == 2);
assert(extent&lt;int[2][4]>::value == 2);
assert(extent&lt;int[][4]>::value == 0);
assert((extent&lt;int, 1>::value) == 0);
assert((extent&lt;int[2], 1>::value) == 0);
assert((extent&lt;int[2][4], 1>::value) == 4);
assert((extent&lt;int[][4], 1>::value) == 4);

- end example]

4.5.3 Array modifications:

Change:

template &lt;class T> struct remove_dimension{
   typedef T type;
};
template &lt;class T, std::size_t N> struct remove_dimension&lt;T[N]>{
   typedef T type;
};
template &lt;class T> struct remove_dimension&lt;T[]>{
   typedefs T type;
};

to:

template &lt;class T> struct remove_extent {
   typedef T type;
};
template &lt;class T, std::size_t N> struct remove_extent&lt;T[N]> {
   typedef T type;
};
template &lt;class T> struct remove_extent&lt;T[]> {
   typedef T type;
};

Change:

[example
  // the following assertions should all hold:
  assert((is_same&lt;remove_dimension&lt;int>::type, int>::value));
  assert((is_same&lt;remove_dimension&lt;int[2]>::type, int>::value));
  assert((is_same&lt;remove_dimension&lt;int[2][3]>::type, int[3]>::value));
  assert((is_same&lt;remove_dimension&lt;int[][3]>::type, int[3]>::value));
end example]

template &lt;class T> struct remove_all_dimensions {
   typedef T type;
};
template &lt;class T, std::size_t N> struct remove_all_dimensions&lt;T[N]> {
   typedef typename remove_all_dimensions&lt;T>::type type;
};
template &lt;class T> struct remove_all_dimensions&lt;T[]> {
   typedef typename remove_all_dimensions&lt;T>::type type;
};

to:

[example
  // the following assertions should all hold:
  assert((is_same&lt;remove_extent&lt;int>::type, int>::value));
  assert((is_same&lt;remove_extent&lt;int[2]>::type, int>::value));
  assert((is_same&lt;remove_extent&lt;int[2][3]>::type, int[3]>::value));
  assert((is_same&lt;remove_extent&lt;int[][3]>::type, int[3]>::value));
end example]

template &lt;class T> struct remove_all_extents {
   typedef T type;
};
template &lt;class T, std::size_t N> struct remove_all_extents&lt;T[N]> {
   typedef typename remove_all_extents&lt;T>::type type;
};
template &lt;class T> struct remove_all_extents&lt;T[]> {
   typedef typename remove_all_extents&lt;T>::type type;
};

Change:

[example
  // the following assertions should all hold:
  assert((is_same&lt;remove_all_dimensions&lt;int>::type, int>::value));
  assert((is_same&lt;remove_all_dimensions&lt;int[2]>::type, int>::value));
  assert((is_same&lt;remove_all_dimensions&lt;int[2][3]>::type, int>::value));
  assert((is_same&lt;remove_all_dimensions&lt;int[][3]>::type, int>::value));
end example]

to:

[example
  // the following assertions should all hold:
  assert((is_same&lt;remove_all_extents&lt;int>::type, int>::value));
  assert((is_same&lt;remove_all_extents&lt;int[2]>::type, int>::value));
  assert((is_same&lt;remove_all_extents&lt;int[2][3]>::type, int>::value));
  assert((is_same&lt;remove_all_extents&lt;int[][3]>::type, int>::value));
end example]

4.5.4 Pointer modifications

Change:

template &lt;class T> struct add_pointer {
   typedef typename remove_dimension&lt;
      typename remove_reference&lt;T>::type
               >::type*
           type;
};

to:

template &lt;class T> struct add_pointer
{
   typedef typename remove_extent
   &lt;
      typename remove_reference&lt;T>::type
   >::type* type;
};

4.6 Implementation requirements

Change:

is_pod&lt;T>::value == is_pod&lt;remove_dimension&lt;T>::type>::value

to:

is_pod&lt;T>::value == is_pod&lt;remove_extent&lt;T>::type>::value

Change:

has_trivial_*&lt;T>::value == has_trivial_*&lt;remove_dimension&lt;T>::type>::value

to:

has_trivial_*&lt;T>::value == has_trivial_*&lt;remove_extent&lt;T>::type>::value
                          
</pre>
</body>
</html>
