Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-10-02 07:19:34


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".

The genericity argument - add_const_to_element - is new, however. Do people
really need such a primitive? Any motivating examples taken from real world
code, preferably with identifier names intact, no Widgets and Foos?


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