title: Context depended template argument deduction - type/value mismatch at argument
body: <p>Minimal example</p>
  <pre><code>#include &lt;vector&gt;
  #include &lt;tuple&gt;
  
  template&lt;typename T&gt;
  void function(std::vector&lt;T&gt; vec)
  {
      auto tup = std::tuple&lt;decltype(vec)::iterator&gt;(vec.begin());
  }
  
  int main(int argc, char* args[])
  {
      std::vector&lt;int&gt; vec = {1,2,3};
  
      auto tup = std::tuple&lt;decltype(vec)::iterator&gt;(vec.begin());
  
      function(vec);
      return 0;
  }
  </code></pre>
  <p>Trying to compile gives</p>
  <pre><code>error: type/value mismatch at argument 1 in template parameter list for ‘template&lt;class ... _Elements&gt; class std::tuple’
  auto tup = std::tuple&lt;decltype(vec)::iterator&gt;(vec.begin());
                                                ^
  note:   expected a type, got ‘decltype (vec)::iterator’
  </code></pre>
  <p>The solution described <a href="https://stackoverflow.com/questions/40827190/decltypesome-vectorsize-type-doesnt-work-as-template-parameter">here</a> suggests adding a <code>typename</code>. Placing <code>typename</code> in front of the <code>decltype</code> in <code>function</code> solves the compilation problem. However:</p>
  <ol>
  <li>Why can the type not be deduced?</li>
  <li>What is the underlying problem? (Obviously the compiler has doubts about decltype(...)::iterator being a type. But why does it work in <code>main</code> but not in <code>function</code>?)</li>
  </ol>