
On 9/16/2011 1:24 PM, Emil Dotchevski wrote:
On Fri, Sep 16, 2011 at 11:11 AM, John M. Dlugosz <mpbecey7gu@snkmail.com> wrote:
I'm wondering why there is not an efficient built-in way to check whether two things (e.g. a shared_ptr and a weak_ptr, but any combination should work) refer to the same object.
It depends what you mean by "refer to the same object". You can use !(p1<p2)&& !(p2<p1) with either shared_ptr or weak_ptr, which will tell you if they manage the lifetime of the same instance (or are both empty), but that doesn't necessarily mean that shared_ptr::get would return the same pointer for both.
I guess that is what I'm trying to figure out. If two smart pointers manage the lifetime of the same entity, how can they not get() the same pointer? I see that they might be different addresses if they refer to the object by different types, but that is true for regular pointers, and bringing them to a common base class would allow them to compare equal.