Boost logo

Boost :

From: Johan Nilsson (johan.nilsson_at_[hidden])
Date: 2002-12-12 08:02:10


"Terje Slettebø" <tslettebo_at_[hidden]> wrote in message
news:082701c2a12f$15c74170$60fb5dd5_at_pc...
> >From: "Eric Woodruff" <Eric.Woodruff_at_[hidden]>
>
> > "Johan Nilsson" <johan.nilsson_at_[hidden]> wrote in message
> > news:at76e1$2ro$1_at_main.gmane.org...
> >
> > Anyhow, in my opinion, dynamic_void_cast is completely unnecessary and
> takes
> > casts away the intent that it is _supposed_ to be a two step and very
ugly
> > process--the signifier that you have a not-so-good design on your hands.
> > Stop trying to code a new messenger.
>
> As Bjarne Stroustrup says in D&E, "Don't fight the type system." You can't
> win. :) Casting does indeed tend to be fighting the type system. Sure, you
> can do it, but you may end up with switch-on-type code, etc., which, as he
> said that some had said it, "has the elegance of C, combined with the
> efficiency of Smalltalk." :) And even that was too nice, he said.
>
> I understand you (Johan) want to be able to have generic factories, but
then
> erasing the type is probably not the way to go, and as has been pointed
out
> in this thread, void * is type erasure. More or less the only safe thing
you
> can do with it, is to delete it. You can also cast it back to its original
> type, but that requires that you know that type to begin with. It doesn't,
> portably, have the possibility to cast to arbitrary type, as you've seen.

I just found a thread called "more flexible any" in the ASPN archives, that
at a first glance looks like something I could use. However I couldn't
compile it under VC.NET. The post was a few months old, don't know what's
happened since that.

>
> As you said it, even COM doesn't use void *, but IUnknown and
> QueryInterface.
>

Well, all COM objects are required to implement IUnknown (which helps :)

// Johan


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