From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-01-08 13:57:51
David Abrahams wrote:
> Angus Leeming <angus.leeming_at_[hidden]> writes:
>> David Abrahams wrote:
>>>> I have this code that use shared_ptr<>::use_count() to
>>>> ascertain whether to remove an item from a cache:
>>>> Is that the sort of thing you are interested in?
>>> Yep, but unique is not quite the same as use_count.
>> I guess that I wrote the code without noticing unique()s existence.
>> However, I now know of it (thanks ;-) and have checked the code in
>> bool unique() const // nothrow
>> return use_count() == 1;
>> I find that this is exactly what I use myself, so will modify my code
>> to use shared_ptr<>::unique().
> Will your code work just as well if unique changed to:
> bool unique() const // nothrow
> return weak_count() == 1;
In this case weak pointers should not prevent remove() from removing the
item from the cache. Presumably, whoever has the weak pointer does not want
it to keep the cache line alive (otherwise he would have used a shared_ptr.)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk