From: Robert Ramey (ramey_at_[hidden])
Date: 2003-11-18 11:14:43


Matthias Troyer wrote:

>Sorry, but if I am not mistaken, I do not see how this can work with
>the following array

>double* p=new double[n];

>since sizeof(p) is just 4 or 8 bytes and sizeof(*p) would be 8 bytes.
>You would have to pass the size of the array n as a second argument.

a pointer to a POD type will invoke a compile time assertion unless overridden
int the archive.

Arrays will work as expected;

double p1[234]
ar << p1

If n is a constant then I think the followng will also work

ar << static_cast<double[n] &>(p)

another idea would be to make your own wrapper. suppose I call
it a pseudo array

template<class T>
struct pseudo_array
{
        size_t m_n;
        T *m_tprr;
        pseudo_array(size_t n, T * tptr) :
                m_n(n), m_tptr(tptr)
        {}
        // default serialization of pseudo array
        template<class Archive>
        void serialize(Archive &ar, const unsigned int file_version){
                ar << m_n;
                T * tptr = m_tptr;
                for(size_t n = m_n; n-- > 0)
                        ar << *tptr++;
        }
};

then you could always use

ar << pseudo_array(n, p);

if you have an archive that supported a special way to handle
a pseudo array of a particular type you can override
serializaton of just that type in just that archive. So you
would maintain archive orthogonality and maximum speed.

Robert Ramey