Title
std::hash<std::filesystem::path> is not enabled
Status
c++23
Section
[fs.class.path]
Submitter
Jiang An

Created on 2022-01-02.00:00:00 last changed 13 months ago

Messages

Date: 2022-02-10.12:58:57

Proposed resolution:

This wording is relative to N4901.

  1. Modify [fs.filesystem.syn], header <filesystem> synopsis, as indicated:

    #include <compare> // see [compare.syn]
    
    namespace std::filesystem {
      // [fs.class.path], paths
      class path;
    
      // [fs.path.nonmember], path non-member functions
      void swap(path& lhs, path& rhs) noexcept;
      size_t hash_value(const path& p) noexcept;
    
      […]
    }
    
    // [fs.path.hash], hash support
    namespace std {
      template<class T> struct hash;
      template<> struct hash<filesystem::path>;
    }
    
    
  2. Following subclause [fs.path.nonmember], introduce a new subclause [fs.path.hash], as indicated:

    29.12.6.? Hash support [fs.path.hash]

    template<> struct hash<filesystem::path>;
    

    -?- For an object p of type filesystem::path, hash<filesystem::path>()(p) evaluates to the same result as filesystem::hash_value(p).

Date: 2022-02-10.00:00:00

[ 2022-02-10 Approved at February 2022 virtual plenary. Status changed: Tentatively Ready → WP. ]

Date: 2022-01-15.00:00:00

[ 2022-01-30; Reflector poll ]

Set status to Tentatively Ready after five votes in favour during reflector poll.

Date: 2022-01-15.00:00:00

[ 2022-01-18; Daniel improves wording based on reflector discussion feedback ]

Date: 2022-01-15.00:00:00

[ 2022-01-15; Daniel provides wording ]

Previous resolution [SUPERSEDED]:

This wording is relative to N4901.

  1. Modify [fs.filesystem.syn], header <filesystem> synopsis, as indicated:

    #include <compare> // see [compare.syn]
    
    namespace std::filesystem {
      // [fs.class.path], paths
      class path;
    
      // [fs.path.nonmember], path non-member functions
      void swap(path& lhs, path& rhs) noexcept;
      size_t hash_value(const path& p) noexcept;
    
      […]
    }
    
    // [fs.path.hash], hash support
    namespace std {
      template<class T> struct hash;
      template<> struct hash<filesystem::path>;
    }
    
    
  2. Following subclause [fs.path.nonmember], introduce a new subclause [fs.path.hash], as indicated:

    29.12.6.? Hash support [fs.path.hash]

    template<> struct hash<filesystem::path>;
    

    -?- For an object p of type filesystem::path, hash<filesystem::path>()(p) shall evaluate to the same result as hash_value(p).

Date: 2022-01-02.00:00:00

The hash support of std::filesystem::path is provided by std::filesystem::hash_value, but the specialization std::hash<std::filesystem::path> is currently disabled. IMO the specialization should be enabled, and its operator() should return the same value as hash_value.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2022-02-10 12:58:57adminsetmessages: + msg12363
2022-02-10 12:58:57adminsetstatus: ready -> wp
2022-01-30 17:01:07adminsetmessages: + msg12308
2022-01-30 17:01:07adminsetstatus: new -> ready
2022-01-18 16:46:24adminsetmessages: + msg12266
2022-01-15 19:52:22adminsetmessages: + msg12265
2022-01-15 19:52:22adminsetmessages: + msg12264
2022-01-02 00:00:00admincreate