[serialization] Removing empty classes

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[serialization] Removing empty classes

Loïc Joly-3
Hello,

Let's say I have a structure suce as this :

class A {};
class B : public A {};
class C : public B {};

Currently, I have some code that looks like this :

template<class Archive>
void C::serialize(Archive &ar,  const unsigned int version)
{
   ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(B);
}

However, if my class B is "empty", that is it adds no data to A, is this
possible as an optimisation to just write :

template<class Archive>
void C::serialize(Archive &ar,  const unsigned int version)
{
   ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
}

Or will this break something ?

--
Loïc

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [serialization] Removing empty classes

Robert Ramey
Loïc Joly wrote:

> Hello,
>
> Let's say I have a structure suce as this :
>
> class A {};
> class B : public A {};
> class C : public B {};
>
> Currently, I have some code that looks like this :
>
> template<class Archive>
> void C::serialize(Archive &ar,  const unsigned int version)
> {
>    ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(B);
> }
>
> However, if my class B is "empty", that is it adds no data to A, is
> this possible as an optimisation to just write :
It should be

>
> template<class Archive>
> void C::serialize(Archive &ar,  const unsigned int version)
> {
>    ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(A);
> }
>
> Or will this break something ?

I doubt it - if you look at the definition of base_object you'll find its
really just a cast to the base class.

Robert Ramey




_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users