|
Boost : |
From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2002-07-19 14:13:54
----- Original Message -----
From: "Peter Dimov" <pdimov_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, July 19, 2002 1:07 PM
Subject: Re: [boost] Re: Logical constness of intrusive_ptr
> From: "Ed Brey" <brey_at_[hidden]>
> >
> > > > 4. I was happy, except for the cases where I my new code had
> > > intrusive_ptr<T const>. So I changed those to back shared_ptr. I
also
> > > noticed that given T const, shared_ptr silently pessimized by not
using
> > > counted_base,
> > > <
> > >
> > > Could you elaborate? What does "not using counted_base" mean here?
This
> may
> > > be a bug.
> >
> > The shared_count constructor overload that takes counted_base* does not
> take counted_base const*, which is what it would get if the shared_ptr's
> template type is <T const>. Overload resolution then falls back on the
> templatized constructor, which uses the heap instead of counted_base.
> <
>
> No, whether the template parameter is const or not doesn't matter. In
>
> shared_ptr<T const> pt(new T);
>
> the type that pt has been initialized with is 'T', not 'T const', just
like
> in
>
> shared_ptr<T const> pt2(new Y);
>
> 'pt2' is initialized with 'Y'.
>
I don't understand this.
What do you mean with "is initialized with T and not T const"?
Consider: (I tested this with 1.28.0)
struct A { void foo() ; void bar() const ; } ;
shared_ptr<A> pa ( new A ) ;
shared_ptr<A const> pca ( new A ) ;
pa->foo() ; // OK
pa->bar() ; // OK
pca->foo() ; // non-const methods calls for constant object
pca->bar() ; // OK.
> The only place where the 'counted_base const *' problem appears in
practice
> (AFAIK) is:
>
> class X: public counted_base // allow this -> shared_ptr conversions
> {
> public:
>
> shared_ptr<X> shared_this()
> {
> return shared_ptr<X>(this); // OK
> }
>
> shared_ptr<X const> shared_this() const
> {
> return shared_ptr<X const>(this); // should be a compile-time
error
It doesn't produce a compile-time error currently. Why should it?
Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk