Boost logo

Boost Users :

Subject: Re: [Boost-users] [Serialization]
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-11-05 18:48:20


"Dylan Klomparens" <dylan.klomparens_at_[hidden]> wrote in message news:2eeaa3230911051501u5030ba22se930f6961d438bcd_at_mail.gmail.com...
  Hello, I have 2 questions regarding the Serialization library:

  =========================

  I have a function that I am using to load a serialized class, called "Configuration". A particular line in the function produces a warning message. Should I be worried about this warning?

  yes

  The function is below, with a comment denoting the warning-producing line.

  void Configuration::Save(const string& Name)
  {
      ofstream Out(Name.c_str());
      if(Out.fail())
          throw runtime_error("Error: unable to save configuration file.");
      boost::archive::text_oarchive Archiver(Out);
      Archiver << *this; // This line produces the warning.
  }

  This is an error produced by the library. Look at the "error stack" (one above the error) to
  see the comments in the code which trip this warnning.
  BTW - people often want to "ar << *this or ar << this" and it almost without exception
  a misunderstanding about how the library should be used. Look at the examples and
  tests.

  The warning is:
  C4308: negative integral constant converted to unsigned type ... error is from file: \boost\mpl\print.hpp line: 51

  =========================

  In a separate question, I'm wondering why this code compiles:
  template<class Archive> void save(Archive& ar, const boost::asio::ip::udp::endpoint& endpoint, unsigned int version)
  {
      unsigned short Port = endpoint.port();
      ar << endpoint.address().to_string();
      ar << Port;
  }

  But this code does not compile:
  template<class Archive> void save(Archive& ar, const boost::asio::ip::udp::endpoint& endpoint, unsigned int version)
  {
      ar << endpoint.address().to_string();
      ar << endpoint.port();
  }

  The only difference is endpoint.port() is stored in a seperate unsigned short.

  AND this is an rvalue. That is, its value is on the stack and it's address cannot be used.
  Hence it cannot be serialized without special considerations.
  I don't know why the first one doesn't fail to compile. It's probably a string
  which is a primitive so no tracking is done so it's OK to do it.
  Robert Ramey

  =========================

  Any help is much appreciated!

  -- Dylan

------------------------------------------------------------------------------

  _______________________________________________
  Boost-users mailing list
  Boost-users_at_[hidden]
  http://lists.boost.org/mailman/listinfo.cgi/boost-users



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net