title: How can I remove this duplicate code when using Boost serialization?
body: <p>In my application I have a number of classes that I want to be able to serialize. So each class whose instances need to be serializeable has the following:</p>
  
  <pre><code>    friend class boost::serialization::access;
      template&lt;class Archive&gt;
      void serialize(Archive&amp; ar, const unsigned int version)
      {
         // ar &amp; (all data members) 
      }
  </code></pre>
  
  <p>To serialize the object I then need to use this code from outside the class:</p>
  
  <pre><code>    ObjectToSerialize obj;
      stringstream ss;
      boost::archive::text_oarchive oa(ss);
      oa &lt;&lt; obj;
  </code></pre>
  
  <p>This second block of code is annoying me because I have to use it everytime I want to serialize an object. Is there any way I can move this code to one location and call it when I need to serialize an object?</p>
  
  <p>I could have an object with this method:</p>
  
  <pre><code>    string serializeObject(Serializable obj)
  </code></pre>
  
  <p>But the problem with this is that there is no way to determine which objects are 'serializable' as there is no supertype that a class must implement when adding boost seriization functionality.</p>
  
  <p>So how can I put this code in one place and only allow objects that are serializable to be passed to the method?</p>