Sort order of boost :: weak_ptr after expiration?

For is boost::weak_ptrdefined operator<, therefore it can be used in associative containers.

My question is: is the sorting order of several objects ordered weak_ptr, even when some of them change to zero? Isn't that a mess with containers like std::set?

Example:

using namespace boost;
shared_ptr<A> sptrA1(new A);
weak_ptr<A> wptrA1 = sptrA1;
weak_ptr<A> wptrA2;

{ // begin Scope 1
    shared_ptr<A> sptrA2(new A);
    wptrA2 = sptrA2;
    assert(wptrA1 < wptrA2); // assert #1
}
assert(wptrA1 < wptrA2); // assert #2
  • Would it be argued that # 2 is always true if statement # 1 is true?
  • Is it wptrA2in the same condition before and after area 1?
+5
source share
3 answers

boost::weak_ptr, operator< . , , operator<, - .

+5

.

+2

Use std :: owner_less. This compares the usage amount indicator, not the pointer itself. For instance:

typedef std::weak_ptr<int> IntWPtr;
std::set<IntWPtr, std::owner_less<IntWPtr> > m_set;
+1
source

All Articles