[Bf-blender-cvs] [e2bbb5b07ed] master: BLI: add default hash for shared_ptr and reference_wrapper

Jacques Lucke noreply at git.blender.org
Mon Sep 6 12:55:27 CEST 2021


Commit: e2bbb5b07edba855b3360ecd6ecd9b6bdb0646f1
Author: Jacques Lucke
Date:   Mon Sep 6 12:54:51 2021 +0200
Branches: master
https://developer.blender.org/rBe2bbb5b07edba855b3360ecd6ecd9b6bdb0646f1

BLI: add default hash for shared_ptr and reference_wrapper

This makes it easier to use these types as keys in Map, Set and VectorSet.

===================================================================

M	source/blender/blenlib/BLI_hash.hh

===================================================================

diff --git a/source/blender/blenlib/BLI_hash.hh b/source/blender/blenlib/BLI_hash.hh
index fbed321534c..11ff7d040aa 100644
--- a/source/blender/blenlib/BLI_hash.hh
+++ b/source/blender/blenlib/BLI_hash.hh
@@ -250,6 +250,20 @@ template<typename T> struct DefaultHash<std::unique_ptr<T>> {
   }
 };
 
+template<typename T> struct DefaultHash<std::shared_ptr<T>> {
+  uint64_t operator()(const std::shared_ptr<T> &value) const
+  {
+    return get_default_hash(value.get());
+  }
+};
+
+template<typename T> struct DefaultHash<std::reference_wrapper<T>> {
+  uint64_t operator()(const std::reference_wrapper<T> &value) const
+  {
+    return get_default_hash(value.get());
+  }
+};
+
 template<typename T1, typename T2> struct DefaultHash<std::pair<T1, T2>> {
   uint64_t operator()(const std::pair<T1, T2> &value) const
   {



More information about the Bf-blender-cvs mailing list