Boost logo

Boost :

From: Joe Gottman (jgottman_at_[hidden])
Date: 2004-08-20 19:15:07

"Jeff Williams" <jwilliams_at_[hidden]> wrote in message[]...
> > 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
> > an idea for an extremely useful new function for shared_ptr. It is
> > to use a shared_ptr<void> in places where a void * would otherwise be
> > While a void * can point to anything, there is no safe way to determine
> > run-time what type it originally pointed to. Casting it to the wrong
> > 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, gregod at, cpdaniel at, john at