How to check if weak_ptr is empty (non-assigned)?

Viewed 16832

Is there a way to distinguish between an assigned (possibly expired) weak_ptr and a non-assigned one.

weak_ptr<int> w1;
weak_ptr<int> w2 = ...;

I understand the following checks for either non-assignment or expiry, but is there a (cheaper?) check for only non-assignment?

if (!w.lock()) { /* either not assigned or expired */ }
2 Answers
Related