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