|
Boost : |
From: David B. Held (dheld_at_[hidden])
Date: 2003-02-27 22:21:06
"Fernando Cacciola" <fcacciola_at_[hidden]> wrote in message
news:b3h60t$s16$1_at_main.gmane.org...
> [...]
> You would like to be dealing with:
>
> optional<B>* and optional<D>*
Yes, exactly.
> but you can do this as well, so I figure that what you really
> need is a 'dynamic-type preserving' conversion between these
> optionals. Something that would allow the following:
>
> D dval ;
> optional<D> dopt(dval);
> optional<B> bopt ( optional_cast<B>(dopt) ) ;
> optional<D> dopt2 ( optional_cast<D>(bopt) ) ;
>
> assert ( dval == *dopt2);
>
> Is this what you need?
No, not at all. What I really need is this:
intrusive_ptr<optional<B> > p(new optional<D>);
I'd like to be able to store a map or vector of ptr<optional<B>>
and have it work polymorphically for B or D.
> If it is, I'm afraid it's not possible:
>
> The problem is that even though the conversion will succeed
> (it would probably work with the current optional as it is now),
> it will inevitably _slice_.
Yes, I realize that. I don't expect optional to do anything magical.
But it would be nice if there were a way for wrappers to preserve
(or "inherit" ;) polymorphic attributes. I imagine there are other
places where this is desirable, so it's too bad that there isn't a
mechanism in the language. I wouldn't even know what kind of
thing to propose, however. The problem is that optional (and
other similar wrappers) don't use value semantics to aggregate
the polymorphic type, or else it could just inherit from it. So how
to specify that a wrapper type should mirror a polymorphic
hierarchy is something of a trick, but I hope it's obvious that it
is useful, and perhaps should be possible.
> [...]
> I think that a solution which uses the PolyOptional<T> technique
> is the only way to go.
> [...]
That looks to be the case. Thanks for the comments, though.
Dave
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk