title: c++ static array wrapper
body: <p>I'm trying to build a wrapper class for static array, which should behave like a standard static array.</p>
  
  <pre><code>int main()
  {
    int t[2][3] = {{77, 2, 3}, {4, 5, 6}};
    auto a = make_array(t);
    auto b = a[0]; // gives a ArrayWrapper&lt;int, 3&gt;
    auto c = b[0]; // gives an int of value 77;
    return 0;
  }
  </code></pre>
  
  <p>So far I've written the following class and construction function:</p>
  
  <pre><code>#include &lt;cstdlib&gt;
  
  template &lt;typename T, size_t N&gt;
  struct ArrayWrapper;
  
  template&lt;typename T, size_t N&gt;
  auto make_array(T const (&amp;tab) [N])
  {
    return ArrayWrapper&lt;T, N&gt;(tab);
  }
  
  
  template &lt;typename T, size_t N&gt;
  struct ArrayWrapper
  {
    ArrayWrapper(T const (&amp;tab)[N])
      : t(tab)
    {
    }
  
    template&lt;typename U, size_t M&gt;
      ArrayWrapper&lt;U, M&gt; operator[] (size_t i)
      {
        return make_array&lt;U, M&gt;(t[i]);
      }
  
    T const &amp; t;
  };
  </code></pre>
  
  <p>Unfortunately, during the affectation of <code>b</code> g++ gives me the following error: </p>
  
  <pre><code>error: no match for ‘operator[]’ (operand types are ‘ArrayPrinter&lt;int [3], 2&gt;’ and ‘int’)
     auto b = a[0];
  </code></pre>
  
  <p>Plus I don't know how to specialize the <code>[] operator</code> to return a basic type when <code>ArrayWrapper</code> just contains has one dimension. I'm guessing I should specialize the operator when T is not an array but I could not make it compile.</p>
  
  <p>Can anyone tell me how to help g++ make the template deduction for the [] operator when T is an array?</p>
  
  <p>Can anyone tell me how to tell the [] operator to return the basic type when T is not an array anymore?</p>