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

2908. The less-than operator for shared pointers could do more

Section: 20.3.2.2.8 [util.smartptr.shared.cmp] Status: C++17 Submitter: United States Opened: 2017-02-03 Last modified: 2020-09-06

Priority: Not Prioritized

View all other issues in [util.smartptr.shared.cmp].

View all issues with C++17 status.

Discussion:

Addresses US 135

The less-than operator for shared pointers compares only those combinations that can form a composite pointer type. With the C++17 wording for the diamond functor, less<>, we should be able to support comparison of a wider range of shared pointers, such that less<>::operator(shared_ptr<A>, shared_ptr<B>) is consistent with less<>::operator(A *, B *).

Proposed change: Replace less<V> with just less<>, and drop the reference to composite pointer types.

[2017-03-02, Kona, STL comments and provides wording]

We talked about this in LWG, and I talked to Alisdair. The status quo is already maximally general (operator less-than in Core always forms a composite pointer type), but we can use diamond-less to significantly simplify the specification. (We can't use less-than directly, due to the total ordering issue, which diamond-less was recently "upgraded" to handle.)

[Kona 2017-03-02]

Accepted as Immediate to resolve NB comment.

Proposed resolution:

This wording is relative to N4640.

  1. Change 20.3.2.2.8 [util.smartptr.shared.cmp] as depicted:

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

    -2- Returns: less<V>()(a.get(), b.get()), where V is the composite pointer type (Clause 5) of shared_ptr<T>::element_type* and shared_ptr<U>::element_type*.