
15 Jul
2005
15 Jul
'05
1:28 a.m.
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