title: Why am I getting "use of parameter 'N' outside of function body"?
body: <p>I'm trying to overload the <code>[]</code> operator so I can have access to the elements of a <code>std::tuple</code>. For some reason I am getting the following errors:</p>
  
  <blockquote>
    <p>prog.cpp:11:73: error: use of parameter ‘N’ outside function body<br>
    prog.cpp:11:73: error: use of parameter ‘N’ outside function body<br>
    prog.cpp:11:73: error: use of parameter ‘N’ outside function body<br>
    prog.cpp:11:89: error: template argument 1 is invalid</p>
  </blockquote>
  
  <p>Pretty weird since most of them are repetitions of the first. And I don't understand why I am getting that error because isn't the whole point of having late return-type is so that we can use parameter for the return-type?</p>
  
  <pre><code>#include &lt;tuple&gt;
  
  template &lt;class... Args&gt;
  struct type_list
  {
      std::tuple&lt;Args...&gt; var;
  
      type_list(Args&amp;&amp;... args) : var(std::forward&lt;Args&gt;(args)...) {}
  
      auto operator[](std::size_t const N) -&gt; typename std::tuple_element&lt;N, std::tuple&lt;Args...&gt;&gt;::type&amp;&amp;
      {
          return std::get&lt;N&gt;(var);
      }
  };
  
  int main()
  {
      type_list&lt;int, int, bool&gt; array(2, 4, true);
  }
  </code></pre>
  
  <p>If anyone can explain why this is happening and how I can get this to work it would be very appreciated. Thanks.</p>