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

2573. [fund.ts.v2] std::hash<std::experimental::shared_ptr<T>> does not work for arrays

Section: 8.2.1 [fund.ts.v2::memory.smartptr.shared] Status: TS Submitter: Tim Song Opened: 2015-12-13 Last modified: 2017-07-30

Priority: 0

View all issues with TS status.

Discussion:

Addresses: fund.ts.v2

The library fundamentals TS does not provide a separate specification for std::hash<std::experimental::shared_ptr<T>>, deferring to the C++14 specification in §20.8.2.7/3:

template <class T> struct hash<shared_ptr<T> >;

-3- The template specialization shall meet the requirements of class template hash (20.9.13). For an object p of type shared_ptr<T>, hash<shared_ptr<T> >()(p) shall evaluate to the same value as hash<T*>()(p.get()).

That specification doesn't work if T is an array type (U[N] or U[]), as in this case get() returns U*, which cannot be hashed by std::hash<T*>.

Proposed resolution:

This wording is relative to N4562.

  1. Insert a new subclause after 8.2.1.3 [fund.ts.v2::memory.smartptr.shared.cast]:

    [Note for the editor: The synopses in [header.memory.synop] and [memory.smartptr.shared] should be updated to refer to the new subclause rather than C++14 §20.8.2.7]

    ?.?.?.? shared_ptr hash support [memory.smartptr.shared.hash]

    template <class T> struct hash<experimental::shared_ptr<T>>;
    

    -1- The template specialization shall meet the requirements of class template hash (C++14 §20.9.12). For an object p of type experimental::shared_ptr<T>, hash<experimental::shared_ptr<T>>()(p) shall evaluate to the same value as hash<typename experimental::shared_ptr<T>::element_type*>()(p.get()).