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.
This commit is contained in:
29
source/blender/blenlib/BLI_utility_mixins.h
Normal file
29
source/blender/blenlib/BLI_utility_mixins.h
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user