Boost logo

Boost :

Subject: Re: [boost] [serialization]Can I pass the grandparent class toBOOST_SERIALIZATION_BASE_OBJECT_NVP?
From: Robert Ramey (ramey_at_[hidden])
Date: 2011-04-03 13:44:02


Takatoshi Kondo wrote:

Hi Takatoshi. Nice hear from you. Havn't heard from you in a while.

... example and expanation in previous post.

> ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(A); // My approach
> // ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(B);

> If I pass it B instead of A, the following exception would be
> occurred. "unregistered void cast struct C<-struct A"

Hmmm ... Are sure you don't mean to say "If I pass it A instead of B"

One of he side effects of BOOST_SERIALIZATION_BASE_OBJECT_NVP(A) (orB)
is to invoke void_cast_register<base class, derived class> ...
I would think that you could skip B in this case. But one would have
to more carefully investigate how this macro is implemented.

Note that if B is implemented as just another macro
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
so things can be done the normal way, I would hope that
a release build would collapse the code to be equivalent
to your method of skipping B.

It's also possible the the macro implementation could be
refined and/or enhanced to permit the skipping of B if it
doesn't do so already.

Note that the tests/examples include one case where
the void cast register is called directly - thereby eliminating
the call to the macro. This short circuits the whole process
and would be the most efficient. This is why I believe that
the macro could be modified to directly pass A instead of B

Robert Ramey


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