Boost logo

Boost :

Subject: Re: [boost] xml?
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-04-09 14:45:36


Stefan Seefeld wrote:
> On 04/09/2010 01:50 PM, Larry Evans wrote:
> > On 04/09/10 11:46, Stewart, Robert wrote:
> >> 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.
> >
> > However if the operation to be performed is implemented as a virtual
> > function, then no dynamic_casting is needed. Just call the virtual
> > function. I thought this was one of the main selling points
> > of virtual functions vs. using a switch statement to cover
> > all elements in a type hierarchy and then performing
> > the operation at the appropriate case clause.

Quite right, if your condition holds. See more below.

> For avoidance of doubt: Does this discussion of virtual methods and
> their virtues wrt. common interfaces have anything to do with the
> original question about whether or not to capture the set of
> types that may be returned by an XPath query in a common base class
> / type hierarchy ?

Yes. You suggested the use of Boost.Variant and Larry questioned whether a Node ABC wouldn't be better.

The issue as you pointed out is that there is no reasonable common base class for the types returned. Integers, elements, etc. have no operations in common to make them useful from a common base class. This, Larry's condition doesn't hold and dynamic_cast becomes necessary to do anything useful with the object returned.

_____
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