[Bf-blender-cvs] [387a97ae42a] functions: experimental lazy init for unique pointers
Jacques Lucke
noreply at git.blender.org
Thu Sep 26 16:51:56 CEST 2019
Commit: 387a97ae42aa614383e2a2ef8ec8f622217e79e5
Author: Jacques Lucke
Date: Thu Sep 26 16:46:52 2019 +0200
Branches: functions
https://developer.blender.org/rB387a97ae42aa614383e2a2ef8ec8f622217e79e5
experimental lazy init for unique pointers
===================================================================
M source/blender/blenlib/BLI_lazy_init_cxx.h
===================================================================
diff --git a/source/blender/blenlib/BLI_lazy_init_cxx.h b/source/blender/blenlib/BLI_lazy_init_cxx.h
index a50e50c479f..277637520c0 100644
--- a/source/blender/blenlib/BLI_lazy_init_cxx.h
+++ b/source/blender/blenlib/BLI_lazy_init_cxx.h
@@ -33,8 +33,9 @@
#pragma once
#include <functional>
-#include <BLI_optional.h>
+#include <memory>
+#include "BLI_optional.h"
#include "BLI_lazy_init.h"
namespace BLI {
@@ -61,3 +62,18 @@ void lazy_init_register(std::function<void()> free_func, const char *name);
#define BLI_LAZY_INIT_STATIC(type, func_name) \
static type &func_name(void); \
BLI_LAZY_INIT(type, func_name)
+
+#define BLI_LAZY_INIT_REF(TYPE, NAME) \
+ static std::unique_ptr<TYPE> NAME##_impl(void); \
+ static TYPE *NAME##_builder(void) \
+ { \
+ static std::unique_ptr<TYPE> value = NAME##_impl(); \
+ BLI::lazy_init_register([]() { delete value.release(); }, #NAME); \
+ return value.get(); \
+ } \
+ TYPE &NAME(void) \
+ { \
+ static TYPE &value = *NAME##_builder(); \
+ return value; \
+ } \
+ std::unique_ptr<TYPE> NAME##_impl(void)
More information about the Bf-blender-cvs
mailing list