[Bf-blender-cvs] [ded4dc77618] master: BLI: add conversion constructor for destruct_ptr

Jacques Lucke noreply at git.blender.org
Mon Jul 5 13:04:14 CEST 2021


Commit: ded4dc77618c105aa6a5d25d480f9e23a1523b93
Author: Jacques Lucke
Date:   Mon Jul 5 12:14:50 2021 +0200
Branches: master
https://developer.blender.org/rBded4dc77618c105aa6a5d25d480f9e23a1523b93

BLI: add conversion constructor for destruct_ptr

This allows converting between different `destruct_ptr` types (which is
just a `std::unique_ptr` with a custom deleter).

The most common use case is to convert from a derived type to
the type of the base class.

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

M	source/blender/blenlib/BLI_memory_utils.hh

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

diff --git a/source/blender/blenlib/BLI_memory_utils.hh b/source/blender/blenlib/BLI_memory_utils.hh
index bdbbda9f0c7..14eca49d126 100644
--- a/source/blender/blenlib/BLI_memory_utils.hh
+++ b/source/blender/blenlib/BLI_memory_utils.hh
@@ -309,6 +309,12 @@ template<typename T> void uninitialized_fill_n(T *dst, int64_t n, const T &value
 }
 
 template<typename T> struct DestructValueAtAddress {
+  DestructValueAtAddress() = default;
+
+  template<typename U> DestructValueAtAddress(const U &)
+  {
+  }
+
   void operator()(T *ptr)
   {
     ptr->~T();



More information about the Bf-blender-cvs mailing list