title: using decltype w/ parameter pack for C++11
body: <p>I'm trying to get the <code>multi_index_t</code> code from the second answer <a href="https://stackoverflow.com/questions/30290535/creating-n-nested-for-loops/30290814#30290814">here</a> answered by davidhigh to work with C++11. C++11 does not support <code>auto&amp;</code> type returns.</p>
  
  <p>I converted the return types for the class, but I don't understand how/if it's possible to support the helper function <code>multi_index()</code> without using C++14.</p>
  
  <p>The code: </p>
  
  <pre><code>#include&lt;array&gt;
  
  template&lt;int dim&gt;
  struct multi_index_t
  {
    std::array&lt;int, dim&gt; size_array;
    template&lt;typename ... Args&gt;
    multi_index_t(Args&amp;&amp; ... args) : size_array(std::forward&lt;Args&gt;(args) ...) {}
  
    struct iterator
    {
      struct sentinel_t {};
      std::array&lt;int, dim&gt; index_array = {};
      std::array&lt;int, dim&gt; const&amp; size_array;
      bool _end = false;
  
      iterator(std::array&lt;int, dim&gt; const&amp; size_array) : size_array(size_array) {}
  
      iterator&amp; operator++() 
      {
        for (int i = 0;i &lt; dim;++i)
        {
          if (index_array[i] &lt; size_array[i] - 1)
          {
            ++index_array[i];
            for (int j = 0;j &lt; i;++j) { index_array[j] = 0; }
            return *this;
          }
        }
        _end = true;
        return *this;
      }
      std::array&lt;int, dim&gt;&amp; operator*()  { return index_array; }
      bool operator!=(sentinel_t) const { return !_end; }
    };
  
    iterator begin() const { return iterator{ size_array }; }
    iterator end() const { return typename iterator::sentinel_t{}; }
  };
  
  
  template&lt;typename ... index_t&gt;
  auto multi_index(index_t&amp;&amp; ... index) // &lt;-- this doesn't compile
  {
    static constexpr int size = sizeof ... (index_t); 
    auto ar = std::array&lt;int, size&gt;{std::forward&lt;index_t&gt;(index) ...};
    return multi_index_t&lt;size&gt;(ar);
  }
  </code></pre>
  
  <p>According to <a href="https://stackoverflow.com/questions/3744400/trailing-return-type-using-decltype-with-a-variadic-template-function">this answer</a>, you can't recursively expand the variadic function template via <code>decltype()</code>. Any ideas? </p>