title: How does std::forward deduce the type of `_Ty`?
body: <p>I'm learning about templates and particularly <code>std::forward</code>; when I check its implementation it uses another class template <code>std::remove_reference</code> in its arguments list:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>template&lt;class _Ty&gt;
  _Ty&amp;&amp; forward(typename remove_reference&lt;_Ty&gt;::type&amp; _Arg)
  {// forward an lvalue as either an lvalue or an rvalue
     // ...
  }
  </code></pre>
  
  <p>btw: I've removed a few things like inline, constexpr, NO_EXCEPT and the body of the function for clarity</p>
  
  <p>I read about how types are deduced when the template parameter is a pointer(<code>_Ty*</code>), reference(<code>_Ty</code>&amp;), universal reference(<code>_Ty</code>) and where its just the type itself (<code>_Ty</code>). In this case it is a reference but it has that added <code>removed_reference&lt;_Ty&gt;::type</code> preceding it; the <code>_Ty</code> and the reference are split by the call to <code>remove_reference</code>. How does the compiler figure out the type of <code>_Ty</code>?</p>
  
  <p>The function template has to figure out the template parameters using the arguments passed in to the function(when not explicitly defining them in the function call) but in this case remove_reference is also a class template that needs to figure out the type of <code>_Ty</code> as well. It seems almost like a catch 22 for me because <code>std::forward</code> needs to figure out <code>_Ty</code> using its function argument but its function argument which is <code>std::remove_reference&lt;_Ty&gt;</code> needs to already know what <code>_Ty</code> is. All This tells me is that I have a flawed understanding of how templates work but I don't know where.</p>