|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-07-14 20:28:20
Joe Gottman wrote:
> Actually, it is possible to distinguish case 1 from case 3:
>
> weak_ptr<Foo> wp = get_weak_ptr();
> if (wp.expired()) {
> weak_ptr emptyPtr; // Default constructed weak_ptr
> if (!(emptyPtr < wp) && !(wp < emptyPtr)) {
Right... you can thank Joe for that, with the latest changes to TR1 (*)
operator< can tell you whether a weak_ptr is empty. The original version did
not guarantee that all empty weak pointers compared equivalent. :-)
So it's possible.
template<class T> bool is_empty( weak_ptr<T> const & wp )
{
weak_ptr<T> empty;
return !(empty < wp) && !(wp < empty);
}
Whether it should be used is another story. :-)
(*) See issue 2.4 in
http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1837.pdf
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk