Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialization] Serializing derived templateclassvia base pointer
From: Robert Ramey (ramey_at_[hidden])
Date: 2013-01-17 17:06:19


> On Jan 17, 2013, at 2:01 PM, "Robert Ramey" <ramey_at_[hidden]> wrote:
>
>> Daniel Mitchell wrote:
>>> Hi everyone, has any progress has been made on a general solution
>>> for this problem? Given classes like these,
>>>
>>> struct base {
>>> template<typename Archive>
>>> void serialize(Archive& ar, unsigned version) { }
>>> virtual ~base() = default;
>>> };
>>>
>>> template<typename T>
>>> struct derived : base {
>>> template<typename Archive>
>>> void serialize(Archive& ar, unsigned version) { ar & data; }
>>> T data;
>>> };
>>>
>>> is it possible to serialize the derived type (with T unknown) via a
>>> base pointer? Sticking a call to register_type<derived> in
>>> derived::serialize doesn't seem to do it.
>>
>> There are several demos in the examples directory which show how to
>> do this.
>>
>> Robert Ramey

Daniel Mitchell wrote:
> Hi Robert, thanks for your reply. Unfortunately I couldn't find any
> of the demos to which you refer, but I did find a 2005 boost-users
> thread on the subject:
>
> http://thread.gmane.org/gmane.comp.lib.boost.user/13244/
>
> In that discussion you said you did not have a general solution. I'm
> just wondering if anything has changed since then e.g maybe C++11
> makes a solution possible.

I looked at this thread and don't think it's relevant to your question.
But then I looked at your question again and see that I don't really
understand it.

case 1

given a virtual base class A and a derived class B, serialize B (and any
other
derivatives of A) through a pointer to the base class A.

This case is amply covered by the documentation and by examples in test
and example library directories - see test_dll_exported, etc..

case 2

we have a class A which is a template so it's declared like:

template<class T>
class A {
...
};

and class B is derived from it. Currently one would have to apply the
"export" or "registration" functionality to each instance of A<T> created.
I believe that the thread referred to above addresses this question.
And indeed, I have no answer to this question. It might be possible
using some version of "enable_if" but I have done no work in this area.

Robert Ramey


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net