Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2004-08-06 14:32:51


From: "troy d.straszheim" <troy_at_[hidden]>
> On Aug 6, 2004, at 5:04 PM, Rob Stewart wrote:
> > Line 1b is a means to make construction from raw pointers more
> > apparent, which is good, I agree. Note that your version can be
> > rewritten like this, too:
> >
> > shared_ptr<Widget> p(rawptr(new Widget(a, b)));
> >
> > Note, however, that "rawptr" is rather terse for something you're
> > trying to call attention to. How about "from_raw_ptr" or
> > "from_raw_pointer?"
>
> Somehow it has got stuck in my head that this should be
> shared_pointer_cast<>, but I'm having trouble justifying it, other than
> that it would look nice next to the dynamic_pointer_cast<> and so
> forth.
>
> shared_ptr<Widget> p = shared_ptr_cast<Widget>(new Widget);

Actually, that's better because there's the potential to
overload/specialize it for other source pointer types, and
because from_raw_pointer(), as suggested, can't be used for any
other destination type and yet purports to be the only such
conversion you'll need. IOW, "from_raw_pointer" doesn't mention
the destination type, while "shared_ptr_cast" does.

OTOH, "from_raw_pointer" could be made to be like C++ casts in
order to make it interoperable with other destination types:

   shared_ptr<Widget> p(from_raw_pointer<shared_ptr<Widget> >(
      new Widget));

Once you see that, you really want to get "_cast" in the name:

   shared_ptr<Widget> p(raw_ptr_cast<shared_ptr<Widget> >(
      new Widget));

("pointer" versus "ptr" would really make it long.)

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

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