Boost logo

Boost :

Subject: Re: [boost] xml?
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-04-09 12:46:31


Stefan Seefeld wrote:
> On 04/09/2010 12:34 PM, Larry Evans wrote:
> > On 04/09/10 10:48, Mathias Gaunard wrote:
> >>
> >> Some could argue that the point of a base class is moot if
> >> you have to downcast it to make anything useful with it,
> >
> > But boost.variant has to do the equivalent of downcasting based on
> > discriminant (the value returned by which()).
>
> No, accessing a member of a union is not really a cast, neither
> conceptually nor technically.

Conceptually, they are doing the same: determining whether the requested type is appropriate and returning the appropriately typed value. However, dynamic_cast does so by comparing RTTI objects, which may be more expensive than the discriminator comparison, and then by apply fixups to the this pointer to account for MI, virtual bases, etc.

What's more, once the dynamic_cast has been done, the various functions calls may still wind up being virtual, depending upon how things are implemented. When using Boost.Variant, the types used could have no virtual functions.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


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