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:
2020-02-10 15:29:17 +01:00
parent ec116e3d49
commit f8df6286c2
2 changed files with 30 additions and 0 deletions

View 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

View File

@@ -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