
On Tue, 2008-04-29 at 15:38 -0700, Emil Dotchevski wrote:
On 4/29/08, Daniel Frey <d.frey@gmx.de> 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