[Bf-blender-cvs] [2f6ea757587] functions-experimental-refactor: move destruct_ptr to BLI

Jacques Lucke noreply at git.blender.org
Fri Oct 18 17:53:25 CEST 2019


Commit: 2f6ea757587a1edf7cd0805052a913a4444ffb97
Author: Jacques Lucke
Date:   Fri Oct 18 16:46:15 2019 +0200
Branches: functions-experimental-refactor
https://developer.blender.org/rB2f6ea757587a1edf7cd0805052a913a4444ffb97

move destruct_ptr to BLI

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

M	source/blender/blenlib/BLI_memory_utils_cxx.h
M	source/blender/simulations/bparticles/node_frontend.cpp

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

diff --git a/source/blender/blenlib/BLI_memory_utils_cxx.h b/source/blender/blenlib/BLI_memory_utils_cxx.h
index 8e80524fc36..c64953919a4 100644
--- a/source/blender/blenlib/BLI_memory_utils_cxx.h
+++ b/source/blender/blenlib/BLI_memory_utils_cxx.h
@@ -89,6 +89,15 @@ template<typename T, typename... Args> std::unique_ptr<T> make_unique(Args &&...
   return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
 }
 
+template<typename T> struct DestructValueAtAddress {
+  void operator()(T *ptr)
+  {
+    ptr->~T();
+  }
+};
+
+template<typename T> using destruct_ptr = std::unique_ptr<T, DestructValueAtAddress<T>>;
+
 }  // namespace BLI
 
 #endif /* __BLI_MEMORY_UTILS_CXX_H__ */
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index 4fa390ac1d8..40ed1667244 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -19,6 +19,7 @@ namespace BParticles {
 
 using BKE::VirtualNode;
 using BKE::VirtualSocket;
+using BLI::destruct_ptr;
 using BLI::MonotonicAllocator;
 using BLI::MultiMap;
 using BLI::rgba_f;
@@ -52,20 +53,11 @@ class InfluencesCollector {
   StringMap<AttributesDeclaration> &m_attributes;
 };
 
-template<typename T> struct DestructFunc {
-  void operator()(T *ptr)
-  {
-    ptr->~T();
-  }
-};
-
 class VTreeData {
  private:
   /* Keep this at the beginning, so that it is destructed last. */
   MonotonicAllocator<> m_allocator;
 
-  template<typename T> using destruct_ptr = std::unique_ptr<T, DestructFunc<T>>;
-
   VTreeDataGraph &m_vtree_data_graph;
   Vector<std::unique_ptr<ParticleFunction>> m_particle_functions;
   Vector<std::unique_ptr<Function>> m_functions;



More information about the Bf-blender-cvs mailing list