
David Abrahams wrote:
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.
Hmmm - looks like a good idea to me. If f() is a non const function, then calling it while saving data could change the state of the data being saved. The library tracks repeated saving of objects and on subsequent saves would only save a handle to the original one. This saves time, space and handles multiple pointers to a single instance. If the process of saving can change the data, then all this breaks down. (not to mention saving - without locking - from multiple threads - which is now permited by the library. If f() can't be made "const" and is used in this way, its likely that this would create an archive which would not load correctly. Finding the source of this error, and correcting its effects would seem to be a nightmare 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(); }
Aaaa - I would have to spend some time to look into that. Robert Ramey