Title
Hash support for pmr::string and friends
Status
c++20
Section
[basic.string.hash][string.syn]
Submitter
Tim Song

Created on 2017-06-14.00:00:00 last changed 37 months ago

Messages

Date: 2017-07-12.01:30:31

Proposed resolution:

This wording is relative to N4659.

  1. Edit [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>;
      }
      
      // [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 [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)).

Date: 2017-07-12.01:30:31

[ 2017-07 Toronto Monday issue prioritization ]

Priority 0; move to Ready

Date: 2017-06-14.00:00:00

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>.

History
Date User Action Args
2021-02-25 10:48:01adminsetstatus: wp -> c++20
2017-11-13 19:01:36adminsetstatus: voting -> wp
2017-10-17 18:34:55adminsetstatus: ready -> voting
2017-07-12 01:30:31adminsetmessages: + msg9344
2017-07-12 01:30:31adminsetstatus: new -> ready
2017-06-14 20:24:59adminsetmessages: + msg9263
2017-06-14 00:00:00admincreate