|
Boost : |
From: Matthias Troyer (troyer_at_[hidden])
Date: 2003-11-18 12:15:44
On Nov 18, 2003, at 5:14 PM, Robert Ramey wrote:
> 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)
Usually the sizes are only determined at runtime
>
> another idea would be to make your own wrapper. suppose I call
> it a pseudo array
> [snip]
> 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.
That's an option, but it would mean to reimplement the serialization of
std::vector, boost::array, boost::multi_array, boost::ublas::matrix and
other containers for each new archive for which I want to use such a
feature. I would thus propose to have this functionality built into the
basic archive classes and used in the serialization of all containers
with array-like storage layout.
Matthias
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk