title: Changing serialization of STL containers when using Boost.Serialization
body: <p>I want to extend the Boost Serialization library in such a way that STL collections are saved to XML archives in a different format than the one provided by the Boost Serialization library.</p>
  
  <p>If I am correct all STL containers pass the following function during serialization:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>// &lt;boost/serialization/collections_save_imp.hpp&gt;
  
  namespace boost{ namespace serialization { namespace stl {
  
  template&lt;class Archive, class Container&gt;
  inline void save_collection(Archive &amp; ar, const Container &amp;s)
  {
      /* ... */
  }
  
  } } }
  </code></pre>
  
  <p>So I tried to overload this function for the <code>xml_oarchive</code>. Here is a little example of my approach:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  #include &lt;boost/archive/xml_oarchive.hpp&gt;
  #include &lt;boost/serialization/vector.hpp&gt;
  
  namespace boost { namespace serialization { namespace stl {
  
  template&lt; typename Container &gt;
  inline void save_collection( boost::archive::xml_oarchive&amp; ar, Container const&amp; s )
  {
    /* My serialization */
  }
  
  } } }
  
  int main()
  {
    {
      boost::archive::xml_oarchive ar( std::cout );
  
      std::vector&lt; int &gt; x;
  
      x.push_back( -1 );
      x.push_back(  1 );
      x.push_back( 42 );
      x.push_back(  0 );
  
      ar &lt;&lt; BOOST_SERIALIZATION_NVP( x );
    }
  
    return 0;
  }
  </code></pre>
  
  <p>It compiles and runs. But it does not call my function, but the one provided by Boost. What do I have to do/change to make my serialization of STL containers work?</p>