]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Allow hashing Optional<T>
authorOwen Avery <powerboat9.gamer@gmail.com>
Fri, 12 May 2023 07:14:29 +0000 (03:14 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:37:19 +0000 (18:37 +0100)
gcc/rust/ChangeLog:

* util/rust-optional.h
(struct std::hash<Optional<T>>): New.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/util/rust-optional.h

index 3b3f110b773ede5b82a2e6f769d54d231fdb240c..658d90faa87f30267139a54dc51f84dfd3db1b50 100644 (file)
@@ -228,6 +228,18 @@ public:
 
 } // namespace Rust
 
+namespace std {
+
+template <typename T> struct hash<Rust::Optional<T>>
+{
+  size_t operator() (const Rust::Optional<T> &op) const
+  {
+    return op.is_some () ? std::hash<T> () (op.get ()) : 0;
+  }
+};
+
+} // namespace std
+
 #ifdef CHECKING_P
 
 void