Boost logo

Boost :

From: troy d.straszheim (troy_at_[hidden])
Date: 2004-08-06 12:09:22


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);

A little wordy, but if you want the event to stand out as Rob suggests,
that would do it. In this case it would be handy:

Base *someFactory(int typetomake);
shared_ptr<Derived> d = shared_ptr_cast<Derived>(someFactory(DERIVED));

I also like the ability to assign to NULL. To me it looks pretty
obviously like the right thing to do...

-t

>> 4. Most importantly, all raw pointers that are assigned to smart
>> pointers must
>> go through the rawptr() function (or rawptr_t<T> type), always making
>> it "explicit". The problem in the example presented earlier, is
>> therefore
>> eliminated.
>
> Right.
>
>> 6. The only obvious problem I see, is the backward compability issue,
>> although
>> it still support the "unprotected but powerful pointer constructor
>> approach",
>> with a slightly different syntax.
>
> The standardized version doesn't have to worry about backward
> compatiblity, fortuntely, so these ideas could be made part of
> that version, even if there is difficulty making the change to
> boost::smart_ptr. The interesting thing is that these changes
> could be made an extension to the current boost::smart_ptr so
> that safer usage is possible, just not required.
>
>> Implementation for shared_ptr
>> =============================
>>
>> rawptr.hpp (new file):
>> ---------------------
>> namespace boost {
>>
>> template <class T> class rawptr_t {
>> public:
>> explicit rawptr_t(T * p) : px(p) {}
>> T* get() const { return px; }
>> private:
>> rawptr_t& operator=(const rawptr_t&);
>> T* px;
>> };
>
> Why not just:
>
> template <typename T>
> struct rawptr_t
> {
> T * p_;
> };
>
> You started with a raw pointer, and you're just trying to give it
> a special type recognized by shared_ptr. Why clutter it with the
> rest of the baggage?
>
> --
> Rob Stewart stewart_at_[hidden]
> Software Engineer http://www.sig.com
> Susquehanna International Group, LLP using std::disclaimer;
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


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