|
Boost Users : |
Subject: Re: [Boost-users] shared_ptr to object in stl set container?
From: Igor R (boost.lists_at_[hidden])
Date: 2011-12-13 11:42:49
> Your program might work, but anyone else who might include your operator<()> definition in their own code will be extremely surprised when this doesn't> work as expected:> Â Â ASSERT_FALSE(shared_ptr<Foo>(new Foo()) == shared_ptr<Foo>(new Foo()));>> When I compare 2 pointers, smart or raw, I want to know if the pointers are equal not the subobjects.
Well, I'd argue with the last sentence, but please note that I wasn't
talking about operator == at all. I mentioned operator <, which is
documented in shared_ptr as follows:
"Returns: an unspecified value such that operator< is a strict weak
ordering as described in section 25.3 [lib.alg.sorting] of the C++
standard; under the equivalence relation defined by operator<, !(a <
b) && !(b < a), two shared_ptr instances are equivalent if and only if
they share ownership or are both empty. Throws: nothing."
So as long as operator< implements strict weak ordering, it's fine.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net