From: Neal Becker (ndbecker2_at_[hidden])
Date: 2005-08-26 14:08:18


Robert Ramey wrote:

> A couple of questions/observations:
>
> a)
> ...
>> template<typename Archive, typename T>
>> inline void save (Archive &ar, const std::complex<T>& z, const
>> unsigned int) {
>> ar << real (z);
>> ar << imag (z);
>> }
>
> I presume that real imag return either primitives(float or double) or
> references to these. So that tracking would not be an issue.
>
>>
>> template<typename Archive, typename T>
>> inline void load (Archive &ar, std::complex<T>& z, const unsigned
>> int) { T i, r;
>> ar >> r;
>> ar >> i;
>> z = std::complex<T> (r, i);
>> }
>
> Hmm, loading to a temporary and then moving to a final destination could
> create an issue with tracking. There are a couple of possibilities:
>
> * if real/imag return references, then reformulate the above to:
> ar >> real(z);
> ar >> imag(z);
> since this is now symetric with the save one could avoid the split
> entirely and simplify it even more.
>
> * use reset_object_address

You and I both wish real() and imag() returned a ref!!! But they don't.

So I have:
template<typename Archive, typename T>
inline void load (Archive &ar, std::complex<T>& z, const unsigned int) {
  T i, r;
  ar >> boost::serialization::make_nvp ("real", r);
  ar >> boost::serialization::make_nvp ("imag", i);
  z = std::complex<T> (r, i);
}

Now how can I use reset_object_address, now that the the addresses of the
real and imag pieces of the constructed object are no longer accessable?