title: std::ostream that invokes a callback for each line
body: <p>I am trying to write a custom <code>std::ostream</code> that invokes a function for every line written to it. That is, I would like the following code to work as documented in comments:</p>
  
  <pre><code>my_output_stream s([] (const std::string&amp; line) { 
      WriteLineToSomeOutput(line); 
  });
  
  s &lt;&lt; "Hello world"; // do not invoke anything. The line has not ended yet!
  s &lt;&lt; ", from Alex" &lt;&lt; std::endl; // here we invoke WriteLineToSomeOutput("hello world, from Alex")
  s &lt;&lt; "What's up"; // do not invoke anything. The line has not ended yet.
  s &lt;&lt; ", doc?!\nHow u doing?\n"; // Now we have two lines. We invoke WriteLineToSomeOutput("What's up, doc?!) and WriteLineToSomeOutput("How u doing?")
  </code></pre>
  
  <p>Note that the data is not written anywhere and not stored anywhere. The only thing that I need the stream to store is the current line that is being aggregated, until we encounter an end of line.</p>
  
  <p>I did not find any easy way of doing so, even when using the boost.Iostreams library. Can I avoid writing my own line tokenizer here by using some built-in facilities of STL and Boost?</p>
  
  <p><strong>Background</strong></p>
  
  <p>The <code>my_output_stream</code> class will be used to adapt between an external library and a logging library used in my application. The external library <strong>requires</strong> that I provide an std::ostream. And I want to log each line that is logged by the external library using my application's logging framework.</p>