Boost logo

Boost :

From: Pavel Vozenilek (pavel_vozenilek_at_[hidden])
Date: 2004-01-06 02:56:02


Robert Ramey" <ramey_at_[hidden]> wrote in message

> >what if I have factory wich creates objects identified
> >by some other value.
[snip]
>
> Anything wrong with this?
>
> color color_from_id(int id);
> int id_from_color(color);
>
> template<class Archive>
> void save(Archive & ar, color c){
> ar << id_from_color(c);
> }
>
> template<class Archive>
> void load(Archive & ar, color & c){
> int id;
> ar >> id
> c = color_from_id(id);
> }
>
>
The factory may allocate new object inside and it may not be possible to
create default constructed object.

If something like this is possible:

 template<class Archive>
 void load(Archive & ar, color** uninitialized_ptr_to_c){
   int id;
   ar >> id
   c* newly_created_c = color_from_id(id);
   (*uninitialized_ptr_to_c) = newly_created_c;
}

/Pavel


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