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

2978. Hash support for pmr::string and friends

Section: 23.4.6 [basic.string.hash], 23.4.2 [string.syn] Status: C++20 Submitter: Tim Song Opened: 2017-06-14 Last modified: 2021-02-25

Priority: 0

View all other issues in [basic.string.hash].

View all issues with C++20 status.

Discussion:

In most cases, std::pmr::meow is a drop-in replacement for std::meow. The exception is std::pmr::{,w,u16,u32}string, because unlike their std:: counterparts, they don't come with enabled std::hash specializations.

The P/R below simply adds std::hash specializations for those four typedefs. An alternative approach, for which wording can be produced if desired, is to make the hash specializations for basic_string allocator-agnostic, similar to the partial specialization of hash for vector<bool>.

[2017-07 Toronto Monday issue prioritization]

Priority 0; move to Ready

Proposed resolution:

This wording is relative to N4659.

  1. Edit 23.4.2 [string.syn], header <string> synopsis, as indicated:

      namespace pmr {
        template <class charT, class traits = char_traits<charT>>
          using basic_string = std::basic_string<charT, traits, polymorphic_allocator<charT>>;
    
        using string    = basic_string<char>;
        using u16string = basic_string<char16_t>;
        using u32string = basic_string<char32_t>;
        using wstring   = basic_string<wchar_t>;
      }
      
      // 23.4.6 [basic.string.hash], hash support
      template<class T> struct hash;
      template<> struct hash<string>;
      template<> struct hash<u16string>;
      template<> struct hash<u32string>;
      template<> struct hash<wstring>;
      template<> struct hash<pmr::string>;
      template<> struct hash<pmr::u16string>;
      template<> struct hash<pmr::u32string>;
      template<> struct hash<pmr::wstring>;
    
      namespace pmr {
        template <class charT, class traits = char_traits<charT>>
          using basic_string = std::basic_string<charT, traits, polymorphic_allocator<charT>>;
    
        using string    = basic_string<char>;
        using u16string = basic_string<char16_t>;
        using u32string = basic_string<char32_t>;
        using wstring   = basic_string<wchar_t>;
      }
    
  2. Edit 23.4.6 [basic.string.hash] as indicated:

      template<> struct hash<string>;
      template<> struct hash<u16string>;
      template<> struct hash<u32string>;
      template<> struct hash<wstring>;
      template<> struct hash<pmr::string>;
      template<> struct hash<pmr::u16string>;
      template<> struct hash<pmr::u32string>;
      template<> struct hash<pmr::wstring>;
    

    -1- If S is one of these string types, SV is the corresponding string view type, and s is an object of type S, then hash<S>()(s) == hash<SV>()(SV(s)).