title: IO-manipulators as template parameters?
body: <p>I'm trying to work with a class, let's call it a <code>stream_wrapper</code>.
  It contains a value of (or a reference to) an <code>std::ostream</code> object as one of its fields.</p>
  <p>All I want to do is to overload the <code>&lt;&lt;</code> operator, so I can use this wrapper like a normal stream.
  My first idea was just to write it as a function template.</p>
  <p>Example:</p>
  <pre class="lang-cpp prettyprint-override"><code>class stream_wrapper
  {
      std::ostream&amp; stream;
  
      template&lt;typename Output&gt;
      friend stream_wrapper&amp; operator&lt;&lt;(stream_wrapper&amp; s, Output output)
  
  public:
      stream_wrapper(std::ostream&amp; stream) : stream(stream) {}
  }
  
  template&lt;typename Output&gt;
  stream_wrapper&amp; operator&lt;&lt;(stream_wrapper&amp; s, Output output)
  {
      s.stream &lt;&lt; output;
      return s;
  }
  </code></pre>
  <p>The idea was that template will be instantiated fine for all types that <code>std::ostream</code>'s <code>operator&lt;&lt;</code> works.</p>
  <p>This works fine with all usual types, but fails when I attempt to pass some stream manipulator, such as <code>std::endl</code>.</p>
  <p>Example:</p>
  <pre class="lang-cpp prettyprint-override"><code>int main()
  {
      stream_wrapper s(std::cout);
      int a = 1;
      double b = 5;
      s &lt;&lt; a &lt;&lt; ' ' &lt;&lt; b &lt;&lt; '\n'; // WORKS
      s &lt;&lt; std::endl; // DOESN'T COMPILE
  }
  </code></pre>
  <p>This fails, because the compiler can't deduce the type of <code>std::endl</code>.</p>
  <p>So, my questions are:</p>
  <ol>
  <li>Is there a way to make it work?</li>
  <li>What type things like <code>std::endl</code> are?</li>
  </ol>
  <p>Thank you!</p>