std::hash<std::filesystem::path>
is not enabledSection: 31.12.6 [fs.class.path] Status: C++23 Submitter: Jiang An Opened: 2022-01-02 Last modified: 2023-11-22
Priority: Not Prioritized
View all other issues in [fs.class.path].
View all issues with C++23 status.
Discussion:
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
.
[2022-01-15; Daniel provides wording]
Previous resolution [SUPERSEDED]:
This wording is relative to N4901.
Modify 31.12.4 [fs.filesystem.syn], header
<filesystem>
synopsis, as indicated:#include <compare> // see 17.11.1 [compare.syn] namespace std::filesystem { // 31.12.6 [fs.class.path], paths class path; // 31.12.6.8 [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>; }Following subclause 31.12.6.8 [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 typefilesystem::path
,hash<filesystem::path>()(p)
shall evaluate to the same result ashash_value(p)
.
[2022-01-18; Daniel improves wording based on reflector discussion feedback]
[2022-01-30; Reflector poll]
Set status to Tentatively Ready after five votes in favour during reflector poll.
[2022-02-10 Approved at February 2022 virtual plenary. Status changed: Tentatively Ready → WP.]
Proposed resolution:
This wording is relative to N4901.
Modify 31.12.4 [fs.filesystem.syn], header <filesystem>
synopsis, as indicated:
#include <compare> // see 17.11.1 [compare.syn] namespace std::filesystem { // 31.12.6 [fs.class.path], paths class path; // 31.12.6.8 [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>; }
Following subclause 31.12.6.8 [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 typefilesystem::path
,hash<filesystem::path>()(p)
evaluates to the same result asfilesystem::hash_value(p)
.