Boost logo

Boost :

Subject: [boost] [serialization] rvalues and const-correctness?
From: David Abrahams (dave_at_[hidden])
Date: 2008-11-06 14:38:34


Consider:

  struct X
  {
      int f();

      template <class Archive>
      void save(Archive& ar, unsigned)
      {
          ar << f(); // can't bind non-const reference to temporary
      }

      BOOST_SERIALIZATION_SPLIT_MEMBER()
  };

This error seems silly to me. Couldn't we add this overload to the
archives, or even simply replace the existing operator with this one?

    template<class T>
    Archive & operator<<(T const & t){
                        // ^^^^^------------- Note
        this->This()->save_override(t, 0);
        return * this->This();
    }
    
TIA,

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk