Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2003-10-30 12:34:39


Vladimir Prus wrote:

>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'm very gratified that someone reads the manual !!! I will elaborate this section
to make it clear that the the macro short hand can't be used for template and
that the serialize override has to be coded explicitly in this case.

>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.

An interesting idea. I've struggled with the static_assert idiom.
I find it indispensable though I'm unhappy with the error message.
I've been putting comments at the right place in the code.

I'm also interested in studying the concept checking library more to adress this
issue

Robert Ramey


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