<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
      "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=us-ascii">
  <title>Proposal to Add Multi-Dimensional Support to std::array</title>
  <meta name="generator" content="Amaya, see http://www.w3.org/Amaya/">
</head>

<body>
<pre>Document number: N3794
Project: Programming Language C++, Library Working Group
Date: 2013-10-10
Reply-to: Daryle Walker &lt;darylew at gmail dot com&gt;</pre>

<h1>Proposal to Add Multi-Dimensional Support to <code>std::array</code></h1>

<h2 id="Ch01">I. Table of Contents</h2>
<ol>
  <li><a href="#Ch01">Table of Contents</a></li>
  <li><a href="#Ch02">Introduction</a></li>
  <li><a href="#Ch03">Motivation and Scope</a></li>
  <li><a href="#Ch04">Impact on the Standard</a></li>
  <li><a href="#Ch05">Design Decisions</a></li>
  <li><a href="#Ch06">Technical Specifications</a></li>
  <li><a href="#Ch07">Acknowledgments</a></li>
  <li><a href="#Ch08">References</a></li>
</ol>

<h2 id="Ch02">II. Introduction</h2>

<p>The <code>std::array</code> class template adapts array types to standard
library classes. But the adaptation is only for the outermost level; the inner
dimensions of a multidimensional array type are not considered. This proposal
is to change <code>std::array</code> to take multiple dimensions as variadic
template arguments.</p>

<h2 id="Ch03">III. Motivation and Scope</h2>

<p>When reading up on the variadic template feature, I made a multidimensional
variant of <code>std::array</code> as an exercise. After making the
single-extent case compatible with <code>std::array</code>, I realized it is
better to propose a change in <code>std::array</code> instead of creating a
near-identical class template. The exercise code, at &lt;<a
href="https://github.com/CTMacUser/ArrayMD">https://github.com/CTMacUser/ArrayMD</a>&gt;,
could be considered as a reference implementation and test suite.</p>

<p>I later found out that a multidimensional array class template was one of
the examples given in the original variadic template proposal.</p>

<p>With constructions that can express array types and array subscript usage in
comma-separated lists, array entities may be invoked during variadic template-
and function-argument processing.</p>

<h2 id="Ch04">IV. Impact on the Standard</h2>

<p>The proposal adds two class templates (and corresponding type-alias
templates), three function templates, and several members to an existing class
template. It modifies descriptions of <code>std::array</code> in the sequence
container requirements. And it modifies the relational operator function
templates to take mixed element types. The implementation should work with
current language features.</p>

<h2 id="Ch05">V. Design Decisions</h2>

<p>I adapted <code>std::array</code> for multidimensional arrays by making the
inner array object a built-in multidimensional array type. Since built-in types
are used, only the first level of access via <code>operator []()</code> has to
be a function instead of a built-in operation. Similar multidimensional
container libraries where the array class template consists of nested
instantiations of itself have the disadvantages of possible padding (making the
elements noncontiguous) and of working in the wrong units (the largest
sub-array type instead of the user's original element type).</p>

<p>The implementation is mostly as straight forward as the current
<code>std::array</code>, so there is not much effort needed from
implementers.</p>

<h2 id="Ch06">VI. Technical Specifications</h2>

<p>The changes are based off C++ Working Draft Standard N3691. The section
numbers for new sections have letters as place-holders; the final numbers, plus
moving existing section numbers to fit, are to be determined later.</p>

<p>In section 20.11.2 [meta.type.synop], change the subsection introducing
array modifications:</p>

<blockquote>
  <pre><i>// 20.11.7.4, array modifications:</i>
template &lt;class T&gt; struct remove_extent;
template &lt;class T&gt; struct remove_all_extents;
<ins>template &lt;class T, size_t I&gt; struct remove_some_extents;
template &lt;class T, size_t... N&gt; struct append_extents;</ins>

template &lt;class T&gt;
  using remove_extent_t = typename remove_extent&lt;T&gt;::type;
template &lt;class T&gt;
  using remove_all_extents_t = typename remove_all_extents&lt;T&gt;::type;
<ins>template &lt;class T, size_t I&gt;
  using remove_some_extents_t = typename remove_some_extents&lt;T, I&gt;::type;
template &lt;class T, size_t... N&gt;
  using append_extents_t = typename append_extents&lt;T, N...&gt;::type;</ins></pre>
</blockquote>

<p>In section 20.11.7.4 [meta.trans.arr], add a third and fourth row to Table
55:</p>

<blockquote>

  <table border="1">
    <caption>Addition to: Table 55 &mdash; Array modifications</caption>
    <thead>
      <tr>
        <th>Template</th>
        <th>Comments</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><pre>template &lt;class T, size_t I&gt;
struct remove_some_extents;</pre>
        </td>
        <td>If <code>I</code> is zero, then the member typedef
          <code>type</code> shall be <code>T</code>. Otherwise, the member
          typedef <code>type</code> shall be the same as applying
          <code>remove_extent</code> <code>I</code> times. [<em>Note:</em> When
          <code>T</code> is either a non-array type or an array type with an
          extent count at most <code>I</code>, this class template acts like
          <code>remove_all_extents</code>. <em>&mdash;end note</em>]</td>
      </tr>
      <tr>
        <td><pre>template &lt;class T, size_t... N&gt;
struct append_extents;</pre>
        </td>
        <td>If <code>N</code> is an empty parameter pack, then the member
          typedef <code>type</code> shall be <code>T</code>. Otherwise, let
          <var><code>X</code></var> be the first entry of <code>N</code>,
          <var><code>Y</code></var> be a (possibly empty) parameter pack
          representing the remainder of <code>N</code>, and
          <var><code>U</code></var> be an alias to <code>typename
          append_extents&lt;T, Y...&gt;::type</code>. Then the member typedef
          <code>type</code> shall alias <code>U[X]</code> when <code>X</code>
          is non-zero, else it shall alias <code>U[]</code>. [<em>Note:</em>
          Since an array of unknown bound is not permitted to be an array
          element type (8.3.4), only the first (i.e. left-most) entry of
          <code>N</code> may be zero. <em>&mdash;end note</em>]</td>
      </tr>
    </tbody>
  </table>
</blockquote>

<p>and add a third example:</p>

<blockquote>
  <p><strong>-3-</strong> [<em>Example</em></p>
  <pre><i>// the following assertions hold:</i>
assert((is_same&lt;remove_some_extents&lt;int, 0&gt;::type, int&gt;::value));
assert((is_same&lt;remove_some_extents&lt;int, 1&gt;::type, int&gt;::value));
assert((is_same&lt;remove_some_extents&lt;int[2], 0&gt;::type, int[2]&gt;::value));
assert((is_same&lt;remove_some_extents&lt;int[2], 1&gt;::type, int&gt;::value));
assert((is_same&lt;remove_some_extents&lt;int[2], 2&gt;::type, int&gt;::value));
assert((is_same&lt;remove_some_extents&lt;int[2][3], 0&gt;::type, int[2][3]&gt;::value));
assert((is_same&lt;remove_some_extents&lt;int[2][3], 1&gt;::type, int[3]&gt;::value));
assert((is_same&lt;remove_some_extents&lt;int[2][3], 2&gt;::type, int&gt;::value));
assert((is_same&lt;remove_some_extents&lt;int[][3], 0&gt;::type, int[][3]&gt;::value));
assert((is_same&lt;remove_some_extents&lt;int[][3], 1&gt;::type, int[3]&gt;::value));
assert((is_same&lt;remove_some_extents&lt;int[][3], 2&gt;::type, int&gt;::value));
assert((is_same&lt;remove_some_extents&lt;int[][3], 3&gt;::type, int&gt;::value));</pre>

  <p><em>&mdash;end example</em>]</p>
</blockquote>

<p>In section 23.2.3 [sequence.reqmts], modify the last column for the last two
rows of Table 101:</p>

<blockquote>

  <table border="1">
    <caption>Modification to: Table 101 &mdash; Optional sequence container
    operations (continued)</caption>
    <thead>
      <tr>
        <th>Expression</th>
        <th>Return type</th>
        <th>Operational semantics</th>
        <th>Container</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><code>a[n]</code></td>
        <td><code>reference</code>; <code>const_reference</code> for constant
          <code>a</code></td>
        <td><code>*(a.begin() + n)</code></td>
        <td><code>basic_string</code>, <code>array</code> <ins>(with one
          extent)</ins>, <code>deque</code>, <code>dynarray</code>,
          <code>vector</code></td>
      </tr>
      <tr>
        <td><code>a.at(n)</code></td>
        <td><code>reference</code>; <code>const_reference</code> for constant
          <code>a</code></td>
        <td><code>*(a.begin() + n)</code></td>
        <td><code>basic_string</code>, <code>array</code> <ins>(with one
          extent)</ins>, <code>deque</code>, <code>dynarray</code>,
          <code>vector</code></td>
      </tr>
    </tbody>
  </table>
</blockquote>

<p>and modify the paragraph that follows that table:</p>

<blockquote>
  <p><strong>-17-</strong> The member function <code>at()</code> provides
  bounds-checked access to container elements. <code>at()</code> throws
  <code>out_of_range</code> if <code>n &gt;= a.size()</code>. <ins>For
  instantiations of <code>array</code> with an extent count besides one, there
  are modifications (23.3.2.D) to the return types and the operational
  semantics of <code>a[n]</code> and <code>a.at()</code>.</ins> </p>
</blockquote>

<p>In section 23.3.1 [sequences.general], modify the "<strong>Header
<code>&lt;array&gt;</code> synopsis</strong>":</p>

<blockquote>
  <pre>#include &lt;initializer_list&gt;
<ins>#include &lt;type_traits&gt;</ins>

namespace std {
  template &lt;class T, size_t<ins>...</ins> N &gt; struct array;
  template &lt;class T, <ins>class U,</ins> size_t<ins>...</ins> N&gt;
    bool operator==(const array&lt;T,N<ins>...</ins>&gt;&amp; x, const array&lt;<del>T</del><ins>U</ins>,N<ins>...</ins>&gt;&amp; y);
  template &lt;class T, <ins>class U,</ins> size_t<ins>...</ins> N&gt;
    bool operator!=(const array&lt;T,N<ins>...</ins>&gt;&amp; x, const array&lt;<del>T</del><ins>U</ins>,N<ins>...</ins>&gt;&amp; y);
  template &lt;class T, <ins>class U,</ins> size_t<ins>...</ins> N&gt;
    bool operator&lt;(const array&lt;T,N<ins>...</ins>&gt;&amp; x, const array&lt;<del>T</del><ins>U</ins>,N<ins>...</ins>&gt;&amp; y);
  template &lt;class T, <ins>class U,</ins> size_t<ins>...</ins> N&gt;
    bool operator&gt;(const array&lt;T,N<ins>...</ins>&gt;&amp; x, const array&lt;<del>T</del><ins>U</ins>,N<ins>...</ins>&gt;&amp; y);
  template &lt;class T, <ins>class U,</ins> size_t<ins>...</ins> N&gt;
    bool operator&lt;=(const array&lt;T,N<ins>...</ins>&gt;&amp; x, const array&lt;<del>T</del><ins>U</ins>,N<ins>...</ins>&gt;&amp; y);
  template &lt;class T, <ins>class U,</ins> size_t<ins>...</ins> N&gt;
    bool operator&gt;=(const array&lt;T,N<ins>...</ins>&gt;&amp; x, const array&lt;<del>T</del><ins>U</ins>,N<ins>...</ins>&gt;&amp; y);
  template &lt;class T, size_t<ins>...</ins> N &gt;
    void swap(array&lt;T,N<ins>...</ins>&gt;&amp; x, array&lt;T,N<ins>...</ins>&gt;&amp; y) noexcept(noexcept(x.swap(y)));

  template &lt;class T&gt; class tuple_size;
  template &lt;size_t I, class T&gt; class tuple_element;
  template &lt;class T, size_t<ins>...</ins> N&gt;
    struct tuple_size&lt;array&lt;T, N<ins>...</ins>&gt; &gt;;
  template &lt;size_t I, class T, size_t<ins>...</ins> N&gt;
    struct tuple_element&lt;I, array&lt;T, N<ins>...</ins>&gt; &gt;;
  template &lt;size_t I, class T, size_t<ins>...</ins> N&gt;
    constexpr T&amp; get(array&lt;T, N<ins>...</ins>&gt;&amp;) noexcept;
  template &lt;size_t I, class T, size_t<ins>...</ins> N&gt;
    constexpr T&amp;&amp; get(array&lt;T, N<ins>...</ins>&gt;&amp;&amp;) noexcept;
  template &lt;size_t I, class T, size_t<ins>...</ins> N&gt;
    constexpr const T&amp; get(const array&lt;T, N<ins>...</ins>&gt;&amp;) noexcept;

  <ins>template &lt;class T, size_t... N, class... Args&gt;
    constexpr array&lt;T, N...&gt; make_array(Args&amp;&amp;...);
  template &lt;class... Args&gt;
    constexpr array&lt;common_type_t&lt;Args...&gt;, sizeof...(Args)&gt;
    make_auto_array(Args&amp;&amp;...);
  template &lt;class TO, size_t... NO, class TI, size_t... NI&gt;
    constexpr array&lt;TO, NO...&gt; reshape_array(const array&lt;TI, NI...&gt;&amp;);</ins>
}</pre>
</blockquote>

<p>Modify section 23.3.2.1 [array.overview]:</p>

<blockquote>
  <p><strong>-1-</strong> The header <code>&lt;array&gt;</code> defines a class
  template for storing fixed-size sequences of objects. An array supports
  random access iterators. An instance of <code>array&lt;T,
  N<ins>...</ins>&gt;</code> stores
  <code><del>N</del></code><ins><code>P</code></ins> elements of type
  <code>T</code>, <ins>where <code>P</code> is the product of the entries from
  the pack expansion <code>N</code>,</ins> so that <code>size() ==
  <del>N</del></code><ins><code>P</code></ins> is an invariant. The elements of
  an array are stored contiguously, meaning that if <code>a</code> is an
  <code>array&lt;T, N<ins>...</ins>&gt;</code> then it obeys the identity
  <code>&amp;<ins>((T*)&amp;</ins>a<ins>)</ins>[n] ==
  &amp;<ins>((T*)&amp;</ins>a<ins>)</ins>[0] + n</code> for all <code>0 &lt;= n
  &lt; <del>N</del></code><ins><code>P</code></ins>.</p>

  <p><strong>-2-</strong> An <code>array</code> is an aggregate (8.5.1) that
  can be initialized with the syntax<br>
  <code>array&lt;T, <del>N</del><ins>N<sub>0</sub>, ...,
  N<sub>sizeof...(N)-1</sub></ins>&gt; a = { <em>initializer-list</em>
  };</code><br>
  where <em>initializer-list</em> is a comma-separated <ins>(and possibly
  braced-partitioned)</ins> list of up to
  <code><del>N</del></code><ins><code>P</code></ins> elements whose types are
  convertible to <code>T</code><ins>, and <code>P</code> is the product of the
  entries <code>N<sub>0</sub></code> through
  <sub></sub><code>N<sub>sizeof...(N)-1</sub></code> from the pack expansion
  <code>N</code></ins>. <ins>[<em>Note:</em> <code>P</code> is <code>1</code>
  when <code>N</code> is empty. <em>&mdash;end note</em>]</ins></p>

  <p><strong>-3-</strong> An <code>array</code> satisfies all of the
  requirements of a container and of a reversible container (23.2), except that
  a default constructed <code>array</code> object is not empty and that
  <code>swap</code> does not have constant complexity. An <code>array</code>
  satisfies some of the requirements of a sequence container (23.2.3).
  Descriptions are provided here only for operations on <code>array</code> that
  are not described in one of these tables and for operations where there is
  additional semantic information.</p>
  <pre>namespace std {
  template &lt;class T, size_t <ins>...</ins>N &gt;
  struct array {
    <i>// types:</i>
    <ins>typedef append_extents_t&lt;T, N...&gt;         type;</ins>
    typedef T&amp;                                reference;
    typedef const T&amp;                          const_reference;
    typedef <i>implementation-defined</i>            iterator;
    typedef <i>implementation-defined</i>            const_iterator;
    typedef size_t                            size_type;
    typedef ptrdiff_t                         difference_type;
    typedef T                                 value_type;
    typedef T*                                pointer;
    typedef const T*                          const_pointer;
    typedef reverse_iterator&lt;iterator&gt;        reverse_iterator;
    typedef reverse_iterator&lt;const_iterator&gt;  const_reverse_iterator;
    <ins>typedef remove_extent_t&lt;type&gt;             dereference;  <i>// iff sizeof...(N) &gt; 0</i></ins>

    <del>T</del><ins>conditional_t&lt;!sizeof...(N) ||
     extent&lt;type&gt;::value, type,
     aligned_storage_t&lt;sizeof(T), alignof(T)&gt;&gt;</ins>       elems<del>[N]</del>;  <i>// exposition only</i>

    <ins>static constexpr size_type
       value_count = sizeof...(N) ? extent&lt;type&gt;::value * sizeof(dereference) / sizeof(value_type) : 1,
      extent_count = sizeof...(N),
         extents[] = { N... };  <i>// iff sizeof...(N) &gt; 0</i></ins>

    <i>// no explicit construct/copy/destroy for aggregate type</i>

    void fill(const T&amp; u);
    void swap(array&amp;) noexcept(noexcept(swap(declval&lt;T&amp;&gt;(), declval&lt;T&amp;&gt;())));
    <ins>template &lt;class F&gt; void apply(F&amp;&amp; f);
    template &lt;class F&gt; void apply(F&amp;&amp; f) const;
    template &lt;class F&gt; void capply(F&amp;&amp; f) const;</ins>

    <i>// iterators:</i>
    iterator begin() noexcept;
    const_iterator begin() const noexcept;
    iterator end() noexcept;
    const_iterator end() const noexcept;

    reverse_iterator rbegin() noexcept;
    const_reverse_iterator rbegin() const noexcept;
    reverse_iterator rend() noexcept;
    const_reverse_iterator rend() const noexcept;

    const_iterator cbegin() const noexcept;
    const_iterator cend() const noexcept;
    const_reverse_iterator crbegin() const noexcept;
    const_reverse_iterator crend() const noexcept;

    <i>// capacity:</i>
    constexpr size_type size() const noexcept;
    constexpr size_type max_size() const noexcept;
    constexpr bool empty() const noexcept;

    <i>// element access:</i>
    <del>reference</del><ins>dereference&amp;</ins> operator[](size_type n);  <ins><i>// iff sizeof...(N) &gt; 0</i></ins>
    constexpr <del>const_reference</del><ins>const dereference&amp;</ins> operator[](size_type n) const;  <ins><i>// iff sizeof...(N) &gt; 0</i></ins>
    <del>reference at(size_type n);
    constexpr const_reference at(size_type n) const;</del>
    <ins>template &lt;class ...SizeType&gt; auto operator()(const SizeType&amp;... n)
     -&gt; remove_some_extents_t&lt;type, sizeof...(SizeType)&gt;&amp;;
    template &lt;class ...SizeType&gt; constexpr auto operator()(const SizeType&amp;... n) const
     -&gt; const remove_some_extents_t&lt;type, sizeof...(SizeType)&gt;&amp;;
    template &lt;class ...SizeType&gt; auto at(const SizeType&amp;... n)
     -&gt; remove_some_extents_t&lt;type, sizeof...(SizeType)&gt;&amp;;
    template &lt;class ...SizeType&gt; constexpr auto at(const SizeType&amp;... n) const
     -&gt; const remove_some_extents_t&lt;type, sizeof...(SizeType)&gt;&amp;;</ins>
    <ins>reference operator[](initializer_list&lt;size_type&gt; i);
    constexpr const_reference operator[](initializer_list&lt;size_type&gt; i) const;
    reference operator()(initializer_list&lt;size_type&gt; i);
    constexpr const_reference operator()(initializer_list&lt;size_type&gt; i) const;
    reference at(initializer_list&lt;size_type&gt; i);
    constexpr const_reference at(initializer_list&lt;size_type&gt; i) const;</ins>
    reference front();
    constexpr const_reference front() const;
    reference back();
    constexpr const_reference back() const;

    <del>T *</del><ins>pointer</ins> data() noexcept;
    <del>const T *</del><ins>const_pointer</ins> data() const noexcept;
  };
}</pre>

  <p><strong>-4-</strong> [ <em>Note:</em> The member variable
  <code>elems</code> is shown for exposition only, to emphasize that
  <code>array</code> is a class aggregate. The name <code>elems</code> is not
  part of <code>array</code>&rsquo;s interface. <em>&mdash;end note</em> ]</p>
</blockquote>

<p>No modifications for section 23.3.2.2 [array.cons]:</p>

<blockquote>
  <p><strong>-1-</strong> The conditions for an aggregate (8.5.1) shall be met.
  Class <code>array</code> relies on the implicitly-declared special member
  functions (12.1, 12.4, and 12.8) to conform to the container requirements
  table in 23.2. In addition to the requirements specified in the container
  requirements table, the implicit move constructor and move assignment
  operator for <code>array</code> require that <code>T</code> be
  <code>MoveConstructible</code> or <code>MoveAssignable</code>,
  respectively.</p>
</blockquote>

<p>Modify section 23.3.2.3 [array.special]:</p>

<blockquote>
  <pre>template &lt;class T, size_t<ins>...</ins> N&gt; void swap(array&lt;T,N<ins>...</ins>&gt;&amp; x, array&lt;T,N<ins>...</ins>&gt;&amp; y) noexcept(noexcept(x.swap(y)));</pre>

  <p><strong>-1-</strong> <em>Effects:</em><br>
  <code>x.swap(y);</code></p>

  <p><strong>-2-</strong> <em>Complexity:</em> linear in
  <code><del>N</del></code><ins><code>array&lt;T,N...&gt;::value_count</code></ins>.</p>
</blockquote>

<p>Add new section 23.3.2.A [array.create], titled "<strong><code>array</code>
creation</strong>":</p>

<blockquote>
  <pre>template &lt;class T, size_t... N, class... Args&gt; constexpr array&lt;T, N...&gt; make_array(Args&amp;&amp;... args);</pre>

  <p><strong>-1-</strong> <em>Requires:</em> <code>sizeof...(Args) &lt;=
  array&lt;T, N...&gt;::value_count</code>. When <code>T</code> is not
  <code>DefaultConstructible</code>, <code>sizeof...(Args) == array&lt;T,
  N...&gt;::value_count</code>. Each type within <code>Args</code> is
  explicitly convertible to <code>T</code>.</p>

  <p><strong>-2-</strong> <em>Returns:</em> an object that is</p>
  <ul>
    <li>value-initialized when <code>sizeof...(Args) == 0</code>,</li>
    <li>else braced-initialized with the pack expansion
      <code>static_cast&lt;T&gt;( forward&lt;Args&gt;(args) )...</code> when
      <code>sizeof...(N) == 0</code> [<em>Note:</em> The braced list is
      ill-formed when <code>sizeof...(Args) &gt; 1</code> (8.5.1).
      <em>&mdash;end note</em>],</li>
    <li>else braced-initialized with a braced list of the pack expansion
      <code>static_cast&lt;T&gt;( forward&lt;Args&gt;(args) )...</code>
      [<em>Note:</em> Unhandled trailing elements get value-initialized. Brace
      elision occurs when <code>sizeof...(N) &gt; 1</code> (8.5.1).
      <em>&mdash;end note</em>].</li>
  </ul>
  <pre>template &lt;class... Args&gt; constexpr array&lt;common_type_t&lt;Args...&gt;, sizeof...(Args)&gt; make_auto_array(Args&amp;&amp;... args);</pre>

  <p><strong>-3-</strong> <em>Requires:</em> <code>sizeof...(Args) &gt;
  0</code>. <code>common_type_t&lt;Args...&gt;</code> is well-formed.</p>

  <p><strong>-4-</strong> <em>Returns:</em>
  <code>make_array&lt;common_type_t&lt;Args...&gt;, sizeof...(Args)&gt;(
  forward&lt;Args&gt;(args)... )</code>.</p>
  <pre>template &lt;class TO, size_t... NO, class TI, size_t... NI&gt; constexpr array&lt;TO, NO...&gt; reshape_array(const array&lt;TI, NI...&gt;&amp; x);</pre>

  <p><strong>-5-</strong> <em>Requires:</em> <code>TO</code> is
  <code>DefaultConstructible</code>. <code>TI</code> is explicitly convertible
  to <code>TO</code>.</p>

  <p><strong>-6-</strong> <em>Returns:</em> an object <code><var>y</var></code>
  such that each <code>*(<var>y</var>.begin() + d)</code> is equivalent to
  <code>static_cast&lt;TO&gt;(*(x.begin() + d))</code> for <code>0 &lt;= d &lt;
  min(x.size(), <var>y</var>.size())</code> and the trailing elements of
  <code><var>y</var></code>, if any, are value-initialized.</p>
</blockquote>

<p>Modify section 23.3.2.4 [array.size]:</p>

<blockquote>
  <pre>template &lt;class T, size_t N&gt; constexpr size_type array&lt;T,N&gt;::size() const noexcept;</pre>

  <p><strong>-1-</strong> <em>Returns:</em>
  <code><del>N</del><ins>value_count</ins></code></p>
</blockquote>

<p>Modify section 23.3.2.5 [array.data]:</p>

<blockquote>
  <pre><del>T *</del><ins>pointer</ins> data() noexcept;</pre>
  <pre><del>const T *</del><ins>const_pointer</ins> data() const noexcept;</pre>

  <p><strong>-1-</strong> <em>Returns:</em> <ins>When <code>extent_count ==
  0</code>, <code>addressof(elems)</code>, otherwise the address of the first
  (possibly nested) element of <code>T</code> in</ins> <code>elems</code>.</p>
</blockquote>

<p>Modify section 23.3.2.6 [array.fill]:</p>

<blockquote>
  <pre>void fill(const T&amp; u);</pre>

  <p><strong>-1-</strong> <em>Effects:</em> <code>fill_n(begin(),
  <del>N</del><ins>value_count</ins>, u)</code></p>
</blockquote>

<p>No modifications for section 23.3.2.7 [array.swap]:</p>

<blockquote>
  <pre>void swap(array&amp; y) noexcept(noexcept(swap(declval&lt;T&amp;&gt;(), declval&lt;T&amp;&gt;())));</pre>

  <p><strong>-1-</strong> <em>Effects:</em> <code>swap_ranges(begin(), end(),
  y.begin())</code></p>

  <p><strong>-2-</strong> <em>Throws:</em> Nothing unless one of the
  element-wise swap calls throws an exception.</p>

  <p><strong>-3-</strong> <em>Note:</em> Unlike the <code>swap</code> function
  for other containers, <code>array::swap</code> takes linear time, may exit
  via an exception, and does not cause iterators to become associated with the
  other container.</p>
</blockquote>

<p>Add new section 23.3.2.B [array.apply]:</p>

<blockquote>
  <pre>template &lt;class F&gt; void apply(F&amp;&amp; f);</pre>
  <pre>template &lt;class F&gt; void apply(F&amp;&amp; f) const;</pre>
  <pre>template &lt;class F&gt; void capply(F&amp;&amp; f) const;</pre>

  <p><strong>-1-</strong> <em>Requires:</em> <code>f</code> is compatible with
  <code>function&lt;void(<var>cv</var> T&amp;, size_type, ...,
  size_type)&gt;</code>, where <var>cv</var> is the cv-qualification of
  <code>*this</code> and the number of trailing <code>size_type</code>
  arguments is <code>extent_count</code>.</p>

  <p><strong>-2-</strong> <em>Effects:</em> <code>f</code> is called once for
  each element with the following constraints:</p>
  <ul>
    <li>Given element <code>e</code> with <code>extent_count</code> ordered
      indices i<sub>0</sub>, ..., i<sub>k</sub> required to dereference it from
      <code>elems</code>, the application call will be compatible with
      <code>forward&lt;F&gt;(f)(e, i<sub>0</sub>, ...,
    i<sub>k</sub>)</code>.</li>
    <li>The order of element traversal is implementation-defined.</li>
  </ul>

  <p><strong>-3-</strong> <em>Throws:</em> Nothing unless an application call
  throws an exception.</p>
</blockquote>

<p><u>Author's Note:</u> Element traversal order should be the in-memory order
or some other order that minimizes cache misses.</p>

<p>Add new section 23.3.2.C [array.iter], titled "<strong><code>array</code>
iteration</strong>":</p>

<blockquote>
  <p><strong>-1-</strong> The beginning value of forward iteration points to
  the element at the address returned by <code>data()</code>. The past-the-end
  value corresponds to <code>data() + value_count</code>. Propagation of
  forward iteration follows the (nested) row-wise storage order (8.3.4).</p>
</blockquote>

<p><u>Author's Note:</u> The above section explicitly defines the intuitive
order elements are linearly visited when the <code>array</code> object is
multidimensional.</p>

<p>Add new section 23.3.2.D [array.access], titled "<strong>Element
access</strong>":</p>

<blockquote>
  <pre>dereference&amp; operator[](size_type n);
constexpr const dereference&amp; operator[](size_type n) const;</pre>

  <p><strong>-1-</strong> <em>Requires:</em> <code>sizeof...(N) &gt; 0</code>
  and <code>n &lt; extents[0]</code>.</p>

  <p><strong>-2-</strong> <em>Returns:</em> <code>elems[n]</code>.</p>

  <p><strong>-3-</strong> <em>Throws:</em> Nothing.</p>
  <pre>template &lt;class ...SizeType&gt; auto operator()(const SizeType&amp;... n)
  -&gt; remove_some_extents_t&lt;type, sizeof...(SizeType)&gt;&amp;;
template &lt;class ...SizeType&gt; constexpr auto operator()(const SizeType&amp;... n) const
  -&gt; const remove_some_extents_t&lt;type, sizeof...(SizeType)&gt;&amp;;</pre>

  <p><strong>-4-</strong> <em>Requires:</em> <code>sizeof...(SizeType) &lt;=
  extent_count</code>. Each entry in the pack expansion <code>SizeType</code>
  has to have an implicit conversion to <code>size_type</code>. Each entry in
  the pack expansion <code>n</code>, in order, needs to be less than the
  corresponding value in <code>extents</code>.</p>

  <p><strong>-5-</strong> <em>Returns:</em> <code>elems</code> followed by
  <code>sizeof...(n)</code> calls of the built-in subscript operator, with each
  operator using an entry from the pack expansion <code>n</code>, in order, as
  an index.</p>

  <p><strong>-6-</strong> <em>Throws:</em> Nothing unless a conversion from an
  entry of the pack expansion <code>n</code> to a <code>size_type</code> value
  throws an exception.</p>

  <p><strong>-7-</strong> <em>Remarks:</em> If any of the types in the pack
  expansion <code>SizeType</code> cannot be implicitly converted to
  <code>size_type</code>, or if <code>sizeof...(SizeType) &gt;
  extent_count</code>, then that function shall not participate in overload
  resolution.</p>
  <pre>reference operator[](initializer_list&lt;size_type&gt; i);
constexpr const_reference operator[](initializer_list&lt;size_type&gt; i) const;
reference operator()(initializer_list&lt;size_type&gt; i);
constexpr const_reference operator()(initializer_list&lt;size_type&gt; i) const;</pre>

  <p><strong>-8-</strong> <em>Requires:</em> <code>i.size() ==
  extent_count</code>. For <code>0 &lt;= d &lt; extent_count</code>,
  <code>*(i.begin() + d) &lt; extents[d]</code>.</p>

  <p><strong>-9-</strong> <em>Returns:</em> <code>operator()(i<sub>0</sub>,
  ..., i<sub>extent_count-1</sub>)</code>, where the <code>i<sub>k</sub></code>
  are the elements of <code>i</code>, in order.</p>

  <p><strong>-10-</strong> <em>Throws:</em> Nothing.</p>
  <pre>template &lt;class ...SizeType&gt; auto at(const SizeType&amp;... n)
  -&gt; remove_some_extents_t&lt;type, sizeof...(SizeType)&gt;&amp;;
template &lt;class ...SizeType&gt; constexpr auto at(const SizeType&amp;... n) const
  -&gt; const remove_some_extents_t&lt;type, sizeof...(SizeType)&gt;&amp;;
reference at(initializer_list&lt;size_type&gt; i);
constexpr const_reference at(initializer_list&lt;size_type&gt; i) const;</pre>

  <p><strong>-11-</strong> <em>Requires:</em> the same requirements as the
  corresponding version of <code>operator()()</code>.</p>

  <p><strong>-12-</strong> <em>Returns:</em> <code>operator()( <var>X</var>
  )</code>, where <var>X</var> is the argument list <code>at()</code>
  received.</p>

  <p><strong>-13-</strong> <em>Throws:</em> Nothing unless: a conversion from
  an entry of the pack expansion <code>n</code> to a <code>size_type</code>
  value throws an exception; a particular index is equal or greater than its
  corresponding entry in <code>extents</code>, in which
  <code>out_of_range</code> is thrown; or <code>i.size() !=
  extent_count</code>, in which <code>length_error</code> is thrown.</p>

  <p><strong>-14-</strong> <em>Remarks:</em> If any of the types in the pack
  expansion <code>SizeType</code> cannot be implicitly converted to
  <code>size_type</code>, or if <code>sizeof...(SizeType) &gt;
  extent_count</code>, then that function shall not participate in overload
  resolution.</p>
</blockquote>

<p><u>Author's Note:</u> The contained (array) object, <code>elems</code>, can
be directly referenced by calling <code>operator()()</code>, <code>at()</code>,
or the <code>initializer_list</code> overload of <code>operator[]()</code> with
no indexes.</p>

<p>Add new section 23.3.2.E [array.extents], titled "<strong>Zero extent
arrays</strong>":</p>

<blockquote>
  <p><strong>-1-</strong> <code>array</code> shall provide support for the
  special case of <code>N</code> being an empty pack expansion.</p>

  <p><strong>-2-</strong> In the case that <code>sizeof...(N) == 0</code>, the
  <code>dereference</code> and <code>extents</code> members are not provided.
  Neither are the overloads of <code>operator[]()</code> that take one
  <code>size_type</code> parameter provided. It is implementation-defined if
  the overloads of <code>operator()()</code> and <code>at()</code> that do not
  take an <code>initializer_list</code> are replaced with equivalent
  non-template members that take zero parameters.</p>
</blockquote>

<p>Modify section 23.3.2.8 [array.zero]</p>

<blockquote>
  <p><strong>-1-</strong> <code>array</code> shall provide support for the
  special case <code><del>N</del><ins>value_count</ins> == 0</code>.
  <ins>[<em>Note:</em> Such <code>array</code> instantiations are made by using
  at least one extent and setting the first extent to zero. They have the same
  size and alignment specifications as instantiations with <code>value_count ==
  1</code>. They are always <code>DefaultConstructible</code>, even when
  <code>T</code> is not. <em>&mdash;end note</em>]</ins></p>

  <p><strong>-2-</strong> In the case that
  <code><del>N</del><ins>value_count</ins> == 0</code>, <ins>the values
  of</ins> <code>begin() <del>==</del></code><ins>and</ins> <code>end()</code>
  <del><code>==</code> unique value</del><ins>are unspecified but they shall be
  identical</ins>. The return value of <code>data()</code> is unspecified.</p>

  <p><strong>-3-</strong> The effect of calling <code>front()</code> or
  <code>back()</code> for a zero-sized array is undefined. </p>

  <p><strong>-4-</strong> Member function <code>swap()</code> shall have a
  <em>noexcept-specification</em> which is equivalent to
  <code>noexcept(true)</code>.</p>
</blockquote>

<p>Modify section 23.3.2.9 [array.tuple]</p>

<blockquote>
  <pre>tuple_size&lt;array&lt;T, N<ins>...</ins>&gt; &gt;::value</pre>

  <p><strong>-1-</strong> <em>Return type:</em> integral constant
  expression.</p>

  <p><strong>-2-</strong> <em>Value:</em> <code><del>N</del><ins>array&lt;T,
  N...&gt;::value_count</ins></code></p>
  <pre>tuple_element&lt;I, array&lt;T, N<ins>...</ins>&gt; &gt;::type</pre>

  <p><strong>-3-</strong> <em>Requires:</em> <code>I &lt;
  <del>N</del><ins>array&lt;T, N...&gt;::value_count</ins></code>. The program
  is ill-formed if <code>I</code> is out of bounds.</p>

  <p><strong>-4-</strong> <em>Value:</em> The type <code>T</code>.</p>
  <pre>template &lt;size_t I, class T, size_t <ins>...</ins>N&gt;
constexpr T&amp; get(array&lt;T, N<ins>...</ins>&gt;&amp; a) noexcept;</pre>

  <p><strong>-5-</strong> <em>Requires:</em> <code>I &lt;
  <del>N</del><ins>array&lt;T, N...&gt;::value_count</ins></code>. The program
  is ill-formed if <code>I</code> is out of bounds.</p>

  <p><strong>-6-</strong> <em>Returns:</em> A reference to the <code>I</code>th
  element of <code>a</code>, where indexing is zero-based <ins>and uses the
  forward-iteration order (23.3.2.C)</ins>.</p>
  <pre>template &lt;size_t I, class T, size_t <ins>...</ins>N&gt;
constexpr T&amp;&amp; get(array&lt;T, N<ins>...</ins>&gt;&amp;&amp; a) noexcept;</pre>

  <p><strong>-7-</strong> <em>Effects:</em> Equivalent to <code>return
  std::move(get&lt;I&gt;(a));</code></p>
  <pre>template &lt;size_t I, class T, size_t <ins>...</ins>N&gt;
constexpr const T&amp; get(const array&lt;T, N<ins>...</ins>&gt;&amp; a) noexcept;</pre>

  <p><strong>-8-</strong> <em>Requires:</em> <code>I &lt;
  <del>N</del><ins>array&lt;T, N...&gt;::value_count</ins></code>. The program
  is ill-formed if <code>I</code> is out of bounds.</p>

  <p><strong>-9-</strong> <em>Returns:</em> A const reference to the
  <code>I</code>th element of <code>a</code>, where indexing is zero-based
  <ins>and uses the forward-iteration order (23.3.2.C)</ins>.</p>
</blockquote>

<p><u>Author's Note:</u> When <code>sizeof...(N) == 1</code>, <code>get</code>
acts with the expected semantics. When <code>N</code> is empty, <code>0</code>
is the only valid value for <code>I</code> and <code>get</code> returns the
sole element. Otherwise, the multiple indexes needed to reference an element
are flattened to the index in "row-major" linear traversal order.</p>

<h2 id="Ch07">VII. Acknowledgements</h2>

<h2 id="Ch08">VIII. References</h2>
<ul>
  <li>A Proposal to Add a Fixed Size Array Wrapper to the Standard Library,
    WG21 Document N15458=03-0131, 2003. <a
    href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1548.htm">www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1548.htm</a>
  </li>
  <li>Variadic Templates (Revision 3), WG21 Document N2080=06-0150, 2006. <a
    href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2080.pdf">www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2080.pdf</a>
  </li>
</ul>
</body>
</html>
