title: Template type deduction for stream manipulators
body: <p>I'm unsure as to whether this code will not compile.</p>
  
  <p>The example code I'm working with:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using std::cout;
  using std::endl;
  
  class Foo {
      public:
          template&lt;typename T&gt;
          Foo&amp; operator&lt;&lt;(const T&amp; t) {
              cout &lt;&lt; t;
              return *this;
          }
  };
  
  int main() {
      Foo foo;
      foo &lt;&lt; "Hello World"; // perfectly fine
      foo &lt;&lt; endl; // shit hits the fan
  
      return 0;
  }
  </code></pre>
  
  <p>This is the error:</p>
  
  <pre><code>test.cpp:19:12: error: no match for ‘operator&lt;&lt;’ in ‘foo &lt;&lt; std::endl’
  test.cpp:19:12: note: candidates are:
  test.cpp:10:14: note: template&lt;class T&gt; Foo&amp; Foo::operator&lt;&lt;(const T&amp;)
  test.cpp:10:14: note:   template argument deduction/substitution failed:
  test.cpp:19:12: note:   couldn't deduce template parameter ‘T’
  </code></pre>
  
  <p>I'm confused as to why it cannot substitute the function type of <code>endl</code> (<code>ostream&amp; (*)(ostream&amp;)</code>) for <code>T</code>, where it clearly is fine with doing it when you specify <code>cout &lt;&lt; endl;</code></p>
  
  <p>I find it additionally puzzling that this fixes the problem [ edited ]</p>
  
  <pre><code>Foo&amp; operator&lt;&lt;(ostream&amp; (*f)(ostream&amp;)) {
      cout &lt;&lt; f;
      return *this;
  }
  </code></pre>
  
  <p>In case the question isn't clear, I'm asking why it could not deduce the template in the first place.</p>