|
Boost : |
From: Joe Gottman (jgottman_at_[hidden])
Date: 2004-08-20 19:15:07
"Jeff Williams" <jwilliams_at_[hidden]> wrote in message
news:20040820121228.RIND12967.fep02.biz.rr.com@[127.0.0.1]...
> > Date: Thu, 19 Aug 2004 21:09:07 -0400
> > From: "Joe Gottman" <jgottman_at_[hidden]>
> > Subject: [boost] shared_ptr feature request: void_pointer_cast
> >
> > I know this isn't the best time to request a new feature, but I just
had
> > an idea for an extremely useful new function for shared_ptr. It is
common
> > to use a shared_ptr<void> in places where a void * would otherwise be
used.
> > While a void * can point to anything, there is no safe way to determine
at
> > run-time what type it originally pointed to. Casting it to the wrong
type
> > can result in undefined behavior.
>
> How is this idea any different that just using
boost::shared_ptr<boost::any> ?
>
shared_ptr<void> is interoperable with shared_ptr<X> for all non-const X.
If you want to use shared_ptr<boost::any>, whoever creates the original
shared_ptr has to declare it as type shared_ptr<boost::any>. With
shared_ptr<void> you can take a type-safe shared_ptr<int> (which may have
been created by third-party code), pass it to non-type-safe code that uses
shared_ptr<void>, then later regain type safety by using void_pointer_cast.
Joe Gottman.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk