title: C++ Decorate basic_iostream classes
body: <p>I want to do something like the following code shows:</p>
  
  <pre><code>class foo
  {
  private:
      std::fstream* m_stream;
  
  public:
      foo(std::fstream* stream) : m_stream(stream) { }
  
      foo&amp; write(char const* s, std::streamsize count)
      {
          if (/*condition*/)
          {
              m_stream-&gt;write(s, count);
          }
          else
          {
              // ...
          }
  
          return *this;
      }
  
      foo&amp; read(char* s, std::streamsize count)
      {
          if (/*condition*/)
          {
              m_stream-&gt;read(s, count);
          }
          else
          {
              // ...
          }
  
          return *this;
      }
  };
  </code></pre>
  
  <p>I would need to add the same behavior to all similar methods (e.g. <code>put</code>). This shouldn't be applied to file streams only, but all other stream classes. Is there any easy way to allow these functionality?</p>