title: Use of typename keyword with template function parameters
body: <p>In C++, the <code>typename</code> keyword is needed so the compiler can disambiguate between nested types and nested values in templates.  However, there are certain situations where no ambiguity is possible, such as when a derived class inherits from a nested class type.</p>
  
  <pre><code>template &lt;class T&gt;
  class Derived : public T::type
  { };
  </code></pre>
  
  <p>Here the <code>typename</code> keyword is not required, and is in fact not even allowed.  This makes sense, because the context removes the ambiguity.  Here, <code>T::type</code> must refer to a type, since you obviously can't inherit from a value.</p>
  
  <p>I would think the same thing would hold true for function template parameters.</p>
  
  <pre><code>template &lt;class T&gt;
  void foo(const T::type&amp; v)
  {
  
  }
  </code></pre>
  
  <p>In this case, the context makes it clear that <code>T::type</code> must refer to a type, since a function parameter can't be a value.  Yet, the compiler doesn't accept this.  It wants <code>const typename T::type&amp;</code>.  This seems inconsistent.  Why does the language allow the implicit assumption of a nested type in the context of inheritance, but <em>not</em> in the context of function parameters?  In both cases there can be no ambiguity, so why the need for <code>typename</code> in one but not the other?</p>