|
Boost : |
From: Vladimir Prus (ghost_at_[hidden])
Date: 2003-10-30 04:36:22
I've just wrote the following:
template<class Archive, class T>
void save(Archive & ar, const boost::scoped_ptr<T> & t, unsigned int version)
{
ar << t.get();
}
template<class Archive, class T>>
void load(Archive & ar, boost::scoped_ptr<T> & t, unsigned int version)
{
T* r;
ar >> r;
t.reset(r);
}
The reason why I wrote save and load, as opposed to 'serialize' are hopefully
clear -- the logic is somewhat different. Now, I'd like serialization lib to
use those functions so I write
BOOST_SERIALIZATION_SPLIT_FREE(
and here I'm stuck, because I can't write scoped_ptr<T> as argument to the
macro -- only concrete type. What am I to do?
Of course, I can declare 'serialize' which does the right thing, but I can do
that only because I looked at the code, which should be be necessary for this
case. So, I believe either docs must cover this use case, or new macros for
templates should be added.
I also have a minor suggestion.
Both iserializer.hpp and oserializer.hpp have the following piece of code.
BOOST_STATIC_ASSERT((^M
mpl::or_<^M
mpl::equal_to<^M
tracking_level<T>, mpl::int_<track_never>^M
>,^M
mpl::greater<^M
implementation_level<T>,^M
mpl::int_<primitive_type>^M
>^M
>::value^M
));^M
When this assert fires, I get
error: invalid application of
`sizeof' to an incomplete type
And that's hard to understand. It would be nice if this assert were factored
out into a separate helper function or class, which can be written like this
(untested code)
template<...>
struct CAN_SAVE_POINTER_TO
{
// same static assert as above.
};
This is just an idea, feel free to toss it.
- Volodya
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk