Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2005-08-26 22:39:54


Neal Becker wrote:
> Robert Ramey wrote:

> OK, so how does this look? This implements std::complex and
> ublas::vector. Does not yet support allocator paramater to
> ublas::vector, but I don't
> think that would be difficult to add.

...

> template<typename Archive, typename T>
> inline void save (Archive &ar, const std::complex<T>& z, const
> unsigned int) {
> ar << boost::serialization::make_nvp ("real", const_cast<const
> T&>(real (z)));
> ar << boost::serialization::make_nvp ("imag", const_cast<const
> T&>(imag (z)));
> }

This doesn't seem right to me. real(z) returns a value. I don't see how
this can be cast to reference to a const value without a lot of (conforming)
compilers objecting. I believe the correct way will be:

const T r = real(z);
ar << boost::serialization::make_nvp ("real", r);
const T i = imag(z);
ar << boost::serialization::make_nvp ("imag", i);

> template<class Archive, class U>
> inline void load (Archive &ar, ublas::vector<U> &v, const unsigned
> int) { unsigned int count;
> ar >> count;
> v.resize (count);
> typename ublas::vector<U>::iterator it = v.begin();
> while (count-- > 0) {
> ar >> *it++;
> }
> }

I wonder about this - but I know nothing of ublas. If v.resize actually
creates the entries I guess it would be just fine. Now I wonder about my
own implementation of serialization for std::vector. It seems yours here is
more efficient.

Robert Ramey


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