Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-11-27 12:08:00


Robert Ramey wrote:

> Changing the names a little bit for clarity, I always anticipated
> archive developers would use something like the following:
>
> template<class T>
> void save(boost::hpc_archive &ar, const std::valarray<T> & t...)
> {
> const unsigned int count = t.size();
> ar << count;
> save_array(ar, get_data(t),t.size());
> }
>
> This would apply the save_array enhancement to all classes derived
> from hpc_archive. In fact I would expect that this is the way people
> are doing it now.

This doesn't work well for several reasons. First, the static type of ar is
hpc_archive, so hpc_archive must be a polymorphic archive base, and this is
not desirable since it's High Performance.

Second, if you add an overload for std::vector:

template<class T>
void save(boost::hpc_archive &ar, const std::vector<T> & t...)

the version in the Serialization library will take precedence since it's an
exact match for the archive argument, and the overload above requires a
derived to base conversion.

Even if it did work, I don't see in which circumstances a class author would
like to _not_ take advantage of the save_array enhancement. Ideally, he
should just call save_array in save, without restricting it to a specific
set of archives. I don't see what you gain by denying him this opportunity -
assuming that it can be provided without negative consequences for the
current code base or existing archive formats.


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