문제

It seems kind of inefficient to have to create a temporary shared_ptr just to see if the weak_ptr is pointing to a valid object. I don't want to even access the object. This is because I have a function that returns a weak_ptr from a vector of shared_ptr and if it returns an empty weak_ptr then that means the object doesn't already exist with that GUID.

So I'm just testing if an object exists.

Is there another way to check to see if the weak_ptr is or isn't empty, without creating a shared_ptr?

도움이 되었습니까?

해결책

You can use the expired() member function.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top