Boost logo

Boost :

From: Daniel Frey (d.frey_at_[hidden])
Date: 2008-04-29 19:00:35


On Tue, 2008-04-29 at 15:38 -0700, Emil Dotchevski wrote:
> On 4/29/08, Daniel Frey <d.frey_at_[hidden]> wrote:
> > I tried to do this and found one thing that I cannot do with the current
> > implementation of weak_ptr: I cannot test if it's empty. It lacks the
> > conversion to bool, similar to shared_ptr. Or is there any way to do
> > this I missed?
> If you have an empty weak_ptr<foo> e, and another weak_ptr<foo> a,
> which you need to test for emptiness, you can use !(e<a) && !(a<e).

Oh. Nice. Although it leaves us with an inefficient and quite ugly
(IMHO) way to test it. But OK, I just asked if it's possible, not if
it's pretty :)

[It still looks stupid if I implement init_weak_once like this:

    void init_weak_once() const
    {
        weak_ptr<T> e;
        if( !( _weak_ptr < e ) && !( e < _weak_ptr ) )
        {
            ...
        }
    }

so maybe, Peter, .empty() would still make sense?]

Regards, Daniel


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