diff options
author | Jacques Lucke <mail@jlucke.com> | 2020-02-10 17:29:17 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2020-02-10 17:33:39 +0300 |
commit | f8df6286c2c05d8480f84d5e5640c4bcb46aa4ad (patch) | |
tree | 9f831ebbf6b1c0d8dfca00559bd745c88144cafa /source/blender/blenlib/BLI_utility_mixins.h | |
parent | ec116e3d492511298c9bf595c19e6c49e07c97f6 (diff) |
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.
Diffstat (limited to 'source/blender/blenlib/BLI_utility_mixins.h')
-rw-r--r-- | source/blender/blenlib/BLI_utility_mixins.h | 29 |
1 files changed, 29 insertions, 0 deletions
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 |