title: serialization of std::map which has member of boost::shared_ptr type fails
body: <p>I'm trying to compare two maps after serialization and deserialization of struct type. It gives me error -- <strong>"error in "MyExample": check <code>e1_i1-&gt;second == e2_i1-&gt;second</code> failed"</strong>.</p>
  
  <p>I'm not able to figure out what could be wrong in below code :</p>
  
  <pre><code>#include &lt;boost/archive/text_oarchive.hpp&gt;
  #include &lt;boost/archive/text_iarchive.hpp&gt;
  #include &lt;boost/serialization/map.hpp&gt; 
  #include &lt;boost/serialization/shared_ptr.hpp&gt;
  
  struct A
  {
  public:
     std::string oldname;
     std::string newname;
  
     friend class boost::serialization::access;
        template&lt;class Archive&gt;
        void serialize(Archive &amp;ar, const unsigned int version)
        {
           ar &amp; oldname;
           ar &amp; newname;
        }
  };
  
  struct Example
  {
  public:
     bool check;
     std::map&lt;std::string,boost::shared_ptr&lt;A&gt;&gt; Atype;
  
     private:
        friend class boost::serialization::access;
        template&lt;class Archive&gt;
        void serialize(Archive &amp;ar, const unsigned int version)
        {
           ar &amp; check;
           ar &amp; Atype;
        }
  };
  
  void set_data(boost::shared_ptr&lt;A&gt; e)
  {
      e-&gt;oldname="a";
      e-&gt;newname="b";
  }
  
  void set_data(Example *e)
  {
     e-&gt;check=false;
  
     // to initialize e-&gt;Atype
     boost::shared_ptr&lt;A&gt; a1 (new A());
     set_data(a1);
     e-&gt;Atype.insert(std::make_pair("a",a1));
  }
  
  void compare_data(std::map&lt;std::string,boost::shared_ptr&lt;A&gt;&gt; e1,std::map&lt;std::string,boost::shared_ptr&lt;A&gt;&gt; e2)
  {
     // because it is of type map, it may be not in proper order   
     typedef std::map&lt;std::string,boost::shared_ptr&lt;A&gt;&gt;::const_iterator i1;
  
     i1 e1_i1= e1.begin();
     i1 e2_i1 =e2.begin();
  
     while ( e1_i1 != e1.end() &amp;&amp; e2_i1 != e2.end()) 
     {
        BOOST_CHECK( e1_i1-&gt;first == e2_i1-&gt;first);
  
        const std::string &amp;key = e1_i1-&gt;first;
        e2_i1 =e2.find(key);
        BOOST_CHECK(e1_i1-&gt;second == e2_i1-&gt;second);
  
        e1_i1++;
        e2_i1++;
      }
  }
  
  void compare_data(Example *e1,Example *e2)
  {
     BOOST_CHECK(e1-&gt;check == e2-&gt;check);
  
     // need to compare e1-&gt;Atype with e2-&gt;Atype
     compare_data(e1-&gt;Atype,e2-&gt;Atype);
  }
  
  BOOST_AUTO_TEST_CASE(MyExample)
  {
     boost::archive::text_oarchive ao(std::cout);
  
     Example c;
     set_data(&amp;c);
  
     const Example &amp; oc=c;
     ao &lt;&lt; oc;
  
     std::stringstream ss; 
     boost::archive::text_oarchive oa(ss);
     oa &lt;&lt; oc;
  
     boost::archive::text_iarchive ia(ss);
  
     Example d;
     ia &gt;&gt; d;
  
     compare_data(&amp;c,&amp;d); 
  
  }
  </code></pre>
  
  <p>I have made sure to include all the header files but here I have not included all.
  Really not sure what could be wrong in above code either setting value of data is incorrect or comparison might be wrong.</p>
  
  <p>different methods for initializing the map which I tried:</p>
  
  <pre><code>// e-&gt;Atype=map_list_of ("a",a1);
  // e-&gt;Atype.insert(std::make_pair("a",a1));
  // e-&gt;Atype.insert(std::map&lt;std::string,boost::shared_ptr&lt;A&gt;&gt;::value_type("a",a1));
  // e-&gt;Atype["a"]=a1;
  </code></pre>
  
  <p>Thanks,</p>