title: Templates for cout input
body: <p>I want to create a function that takes in anything that the <code>&lt;&lt;</code> operator for <code>std::cout</code> can handle. I have an example that breaks.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  template &lt;typename T&gt;
  void my_print(const T &amp;t) {
    std::cout &lt;&lt; t;
  }
  
  int main() {
    my_print("hello\n"); // works
    my_print(4); // works
    my_print(std::endl); // compiler error
    return 0;
  }
  </code></pre>
  
  <p>It also fails if I change to <code>void my_print(T t)</code>. The compiler error is</p>
  
  <pre>error: no matching function for call to 'my_print(&lt;unresolved overloaded function type&gt;)'
  note: candidate is
  note: template&lt;class T&gt; void my_print(const T&amp;)</pre>
  
  <p>Why can't the compiler resolve it when it sees that the argument <code>t</code> is being put into <code>cout</code>?</p>
  
  <p>Is there any good way to fix this or do I have to manually provide the additional <code>&lt;&lt;</code> cases, e.g. <code>void my_print(ostream&amp; (*pf)(ostream&amp;));</code></p>
  
  <p>EDIT: I know <code>endl</code> is a function. Is the answer then that function types are not accepted as templates? Like I can't have <code>[T = ostream&amp; (*)(ostream&amp;)]</code>?</p>