From 7aacdd05bd4d6fa1305d6671521dd01d28b622c3 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 3 Jun 2022 02:10:06 -0600 Subject: [PATCH] [cplusplus] Test hashing shared_ptr / unique_ptr --- test/api/test-cplusplus.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/api/test-cplusplus.cc b/test/api/test-cplusplus.cc index d742750f6..28b5e21ab 100644 --- a/test/api/test-cplusplus.cc +++ b/test/api/test-cplusplus.cc @@ -62,6 +62,7 @@ #include "hb-cplusplus.hh" #include +#include #include int @@ -108,5 +109,16 @@ main () hb::unique_ptr pb5 {pb3.reference ()}; + + /* Test that shared_ptr / unique_ptr are std::hash'able, and that they + * return the same hash (which is the underlying pointer's hash. */ + std::hash hash {}; + std::hash> hash2 {}; + std::hash> hash3 {}; + + assert (hash (b) == hash2 (pb4)); + assert (hash2 (pb4) == hash2 (pb2)); + assert (hash (b) == hash3 (pb5)); + return pb == pb.get_empty () || pb == pb2; }