libstdc++: Define std::hash<std::filesystem::path> (LWG 3657)
authorJonathan Wakely <jwakely@redhat.com>
Mon, 25 Apr 2022 17:21:57 +0000 (18:21 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 26 Apr 2022 12:22:18 +0000 (13:22 +0100)
This DR was approved at the February 2022 plenary.

libstdc++-v3/ChangeLog:

* include/bits/fs_path.h (hash<filesystem::path>): Define.
* testsuite/27_io/filesystem/path/nonmember/hash_value.cc:
Check std::hash specialization.

libstdc++-v3/include/bits/fs_path.h
libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/hash_value.cc

index 9e06fa6..d6202fd 100644 (file)
@@ -1416,6 +1416,16 @@ extern template class __shared_ptr<const filesystem::filesystem_error::_Impl>;
 
 /// @endcond
 
+// _GLIBCXX_RESOLVE_LIB_DEFECTS
+// 3657. std::hash<std::filesystem::path> is not enabled
+template<>
+  struct hash<filesystem::path>
+  {
+    size_t
+    operator()(const filesystem::path& __p) const noexcept
+    { return filesystem::hash_value(__p); }
+  };
+
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
 
index 6bc6296..0dcea6e 100644 (file)
@@ -42,9 +42,19 @@ test02()
   }
 }
 
+void
+test03()
+{
+  std::hash<path> h;
+  // LWG 3657. std::hash<std::filesystem::path> is not enabled
+  for (const path p : __gnu_test::test_paths)
+    VERIFY( h(p) == hash_value(p) );
+}
+
 int
 main()
 {
   test01();
   test02();
+  test03();
 }