title: Using boost::archive with boost::iostreams to compress data
body: <p>I want to write a serialize function for a class that can optionally compress the data.  I would like to use the compression facilities provided in boost::iostreams.  Does anyone know how to do this?</p>
  
  <pre><code>struct X
  {
      X() {}
  
      template&lt;class Archive&gt;
      void serialize(Archive &amp; ar, const unsigned int version)
      {
          ar &amp; compression;
          if(compression == 0)
          {
              ar &amp; data;
          }
          else if(compression == 1)
          {
              // use boost::iostream compression
              // facilities to serialize data
          }
      }
  
      int compression;
      std::vector&lt;int&gt; data;
  };
  </code></pre>