This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++11 status.

1231. weak_ptr comparisons incompletely resolved

Section: [util.smartptr.weak.obs] Status: C++11 Submitter: Daniel Krügler Opened: 2009-10-10 Last modified: 2017-02-03

Priority: Not Prioritized

View all other issues in [util.smartptr.weak.obs].

View all issues with C++11 status.


The n2637 paper suggested several updates of the ordering semantics of shared_ptr and weak_ptr, among those the explicit comparison operators of weak_ptr were removed/deleted, instead a corresponding functor owner_less was added. The problem is that n2637 did not clearly enough specify, how the previous wording parts describing the comparison semantics of weak_ptr should be removed.

[ 2009-11-06 Howard adds: ]

Moved to Tentatively Ready after 5 positive votes on c++std-lib.

Proposed resolution:

  1. Change 23.11.4 [util.smartptr.weak]/2 as described, the intention is to fix the now no longer valid requirement that weak_ptr is LessComparable [Note the deleted comma]:

    Specializations of weak_ptr shall be CopyConstructible, and CopyAssignable, and LessThanComparable, allowing their use in standard containers.

  2. In [util.smartptr.weak.obs] remove the paragraphs 9-11 including prototype:

    template<class T, class U> bool operator<(const weak_ptr<T>& a, const weak_ptr<U>& b);

    Returns: an unspecified value such that

    • operator< is a strict weak ordering as described in 25.4;
    • under the equivalence relation defined by operator<, !(a < b) && !(b < a), two weak_ptr instances are equivalent if and only if they share ownership or are both empty.

    Throws: nothing.

    [Note: Allows weak_ptr objects to be used as keys in associative containers. — end note]