diff options
author | Jacques Lucke <jacques@blender.org> | 2022-03-29 10:19:35 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2022-03-29 10:29:09 +0300 |
commit | d7c644211898185579597588bb4fc08edc1a5093 (patch) | |
tree | dbfbfe7e6a324db29c658e4562583fdebbe39f6f /source/blender/blenlib/BLI_cpp_type_make.hh | |
parent | d4bdf2192964f786520c774d1a2ee44617302bc1 (diff) |
BLI: support value initialization in CPPType
Value initialization differs from default-construction in that it
also zero-initializes trivial types.
Diffstat (limited to 'source/blender/blenlib/BLI_cpp_type_make.hh')
-rw-r--r-- | source/blender/blenlib/BLI_cpp_type_make.hh | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_cpp_type_make.hh b/source/blender/blenlib/BLI_cpp_type_make.hh index 9100b2b9a0f..2612348075b 100644 --- a/source/blender/blenlib/BLI_cpp_type_make.hh +++ b/source/blender/blenlib/BLI_cpp_type_make.hh @@ -20,6 +20,16 @@ template<typename T> void default_construct_indices_cb(void *ptr, IndexMask mask mask.foreach_index([&](int64_t i) { new (static_cast<T *>(ptr) + i) T; }); } +template<typename T> void value_initialize_cb(void *ptr) +{ + new (ptr) T(); +} + +template<typename T> void value_initialize_indices_cb(void *ptr, IndexMask mask) +{ + mask.foreach_index([&](int64_t i) { new (static_cast<T *>(ptr) + i) T(); }); +} + template<typename T> void destruct_cb(void *ptr) { (static_cast<T *>(ptr))->~T(); @@ -186,6 +196,8 @@ CPPType::CPPType(CPPTypeParam<T, Flags> /* unused */, StringRef debug_name) if constexpr (std::is_default_constructible_v<T>) { default_construct_ = default_construct_cb<T>; default_construct_indices_ = default_construct_indices_cb<T>; + value_initialize_ = value_initialize_cb<T>; + value_initialize_indices_ = value_initialize_indices_cb<T>; static T default_value; default_value_ = (void *)&default_value; } |