[Bf-blender-cvs] [f8df6286c2c] master: BLI: add utilities for defining non-movable and non-copyable classes

Jacques Lucke noreply at git.blender.org
Mon Feb 10 15:33:50 CET 2020


Commit: f8df6286c2c05d8480f84d5e5640c4bcb46aa4ad
Author: Jacques Lucke
Date:   Mon Feb 10 15:29:17 2020 +0100
Branches: master
https://developer.blender.org/rBf8df6286c2c05d8480f84d5e5640c4bcb46aa4ad

BLI: add utilities for defining non-movable and non-copyable classes

Structs and classes can subclass these member-free classes privately.
Then they become non-movable, non-copyable or both.

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

A	source/blender/blenlib/BLI_utility_mixins.h
M	source/blender/blenlib/CMakeLists.txt

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

diff --git a/source/blender/blenlib/BLI_utility_mixins.h b/source/blender/blenlib/BLI_utility_mixins.h
new file mode 100644
index 00000000000..66164fdcd24
--- /dev/null
+++ b/source/blender/blenlib/BLI_utility_mixins.h
@@ -0,0 +1,29 @@
+#pragma once
+
+namespace BLI {
+
+class NonCopyable {
+ public:
+  /* Disable copy construction and assignment. */
+  NonCopyable(const NonCopyable &other) = delete;
+  NonCopyable &operator=(const NonCopyable &other) = delete;
+
+  /* Explicitly enable default construction, move construction and move assignment. */
+  NonCopyable() = default;
+  NonCopyable(NonCopyable &&other) = default;
+  NonCopyable &operator=(NonCopyable &&other) = default;
+};
+
+class NonMovable {
+ public:
+  /* Disable move construction and assignment. */
+  NonMovable(NonMovable &&other) = delete;
+  NonMovable &operator=(NonMovable &&other) = delete;
+
+  /* Explicitly enable default construction, copy construction and copy assignment. */
+  NonMovable() = default;
+  NonMovable(const NonMovable &other) = default;
+  NonMovable &operator=(const NonMovable &other) = default;
+};
+
+}  // namespace BLI
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 2780e2becf8..1e4e07d63b3 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -243,6 +243,7 @@ set(SRC
   BLI_utildefines_iter.h
   BLI_utildefines_stack.h
   BLI_utildefines_variadic.h
+  BLI_utility_mixins.h
   BLI_uvproject.h
   BLI_vector.h
   BLI_vector_set.h



More information about the Bf-blender-cvs mailing list