Issue 3657: std::hashstd::filesystem::path is not enabled (original) (raw)


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

3657. std::hash<std::filesystem::path> is not enabled

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

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

    #include // see 17.12.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 struct hash;
    template<> struct hashfilesystem::path;
    }

  2. 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 hashfilesystem::path;

    -?- For an object p of type filesystem::path, hash<filesystem::path>()(p)shall evaluate to the same result as hash_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.

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

    #include // see 17.12.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 struct hash;
    template<> struct hashfilesystem::path;
    }

  2. 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 hashfilesystem::path;

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