Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2002-07-17 11:29:30


----- Original Message -----
From: "Peter Dimov" <pdimov_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, July 17, 2002 12:37 PM
Subject: Re: [boost] Logical constness of intrusive_ptr

> From: "Fernando Cacciola" <fcacciola_at_[hidden]>
> > From: "Peter Dimov" <pdimov_at_[hidden]>
> >
> > > From: "Ed Brey" <brey_at_[hidden]>
> > > > Currently intrusive_ptr<T const> is not supported, ultimately
because
> > > counted_base::use_count_ is not mutable. To me it seems like the
count
> of
> > > references to an object are unrelated to its logical constness. What
do
> > > others think?
> > > <
> > >
> > > Nontrivial question. I don't have enough experience with it yet in
order
> > to
> > > decide.
> > >
> > FWIW, my own intrusive pointer uses a mutable count. It's been working
> fine
> > for nearly half a decade now, so I would say that having a mutable count
> is
> > OK AFAICT.
> >
> > > In the general case, intrusive_ptr<> doesn't really know whether the
> count
> > > is part of the object state. It all depends on how
intrusive_ptr_add_ref
> > > (release) is defined for the specific type; if it takes const
pointers,
> > > intrusive_ptr<T const> should work fine.
> > >
> > I think it should take const pointers.
>
> My point was that intrusive_ptr<> doesn't constrain this in any way; it's
> your choice.
>
You'are right.
I was thinking of intrusive_ptr<> not only as itself alone, but as its
combination with counted_base and the overload of intrusive_ptr_add_ref for
counted_base.
Thus, I meant to say that the intrusive_ptr_add_ref, etc.. should take
"counted_base const*"; and that as a guide, user defined overloads of these
helpers should also take const pointers in order to allow intrusive_ptr<T
const>.
Still, your remark is useful since in case I don't want a mutable count all
I need to do is to overload the helper functions for non-const pointers
only.

> > > In the specific case of objects derived from counted_base, either
choice
> > > seems plausible, since there's the option of using shared_ptr<T const>
> to
> > > denote const objects.
> > >
> > I think counted_base::add_ref(),release(),dispose(),etc.. should all be
> > const.
> >
> >
> >
> > P.S: I noticed while inspecting the latest boost code that
> > 'intrusive_ptr.hpp' doesn't include 'detail\shared_count.hpp'.
> > Should it? I might want to use only intrusive_ptr<>, not shared_ptr<>.
>
> intrusive_ptr, by itself, doesn't depend on counted_base, but you are
right
> that counted_base should probably live in its own separate (non-detail)
> header, boost/counted_base.hpp perhaps.
>
Indeed. This would be appropriate, IMO.

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