Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-10-02 07:07:55


From: "Peter Dimov" <pdimov_at_[hidden]>

> From: "David B. Held" <dheld_at_[hidden]>
> >
> > That is, with my proposal,
>
> [ having shared_ptr propagate constness ]
>
> > I believe that the following would work
> > correctly, and with negligible side effects:
> >
> > void g(foo_ptr const& p)
> > {
> > p->bar();
> > p->baz(3); // Error! (Correct)
> > }
>
> We went over this a few times here and on comp.lang.c++.moderated.
>
> Shallow copy pointers, including raw pointers, typically don't propagate
> constness. It makes little sense for them to do so, as you can always
obtain
> a non-const pointer from a const one and then proceed to modify the
object
> through it. It is true that propagating constness is convenient in
certain
> situations but most people (me included) don't consider the convenience
> factor enough of a justification. We already have one smart pointer where
> pass by value and pass by const reference mean completely different
things.
> :-)
>
> shared_ptr is "as close to raw pointers as possible but no closer".

Why don't you stick this in the smart pointer FAQ?

-----------------------------------------------------------
           David Abrahams * Boost Consulting
dave_at_[hidden] * http://www.boost-consulting.com


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