From: me22 (me22.ca_at_[hidden])
Date: 2007-06-17 20:00:34
On 08/06/07, Alex Burton <alexibu_at_[hidden]> wrote:
> I understand there would be a collision with boost::weak_ptr, which is used for special scenarios with shared_ptr as I understand.
weak_ptr is essential for breaking cyclic references.
> A fair comment would be that this class actually does nothing, that a normal pointer would do and this is true.
raw_ptr might be a better name, then. It's less than weak, since weak
pointers are actually quite intelligent, knowing whether or not
> It allows my code to be free of the * pointer notation.
> All pointers look the same, ie shared_ptr<Foo>, scoped_ptr<Foo>, weak_ptr<Foo>
Those smart pointers are all well-behaved, though. raw pointers are not.
> It can be used in many places a reference would be used.
You can't get the address of temporaries, so I don't understand where
you'd use it in place of references...
> In the above code, if vector<Foo> foos was changed to vector< shared_ptr<Foo> > the code will still work perfectly with out change.
> I find this really useful because often small structs become polymorphic classes (requiring shared_ptr) as code evolves.
> The vector example is the best, but even when returning a pointer to something like this it is good:
> if Bar mBar becomes scoped_ptr<Bar> mBar, the accessor still compiles.
For your vector example, have you considered starting with
vector<Foo>, then changing to ptr_vector<IFoo> later? I think that'll
get you the same effect, but it's much safer.
That constructor from a reference also looks like it'd be far too easy
to mistakenly return a pointer to a local variable. I'm not convinced
that your method is much superior to returning a reference and, if the
member does become a pointer, just adding the * to dereference it in
Probably not quite following just yet,
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk