diff options
author | HampusM <hampus@hampusmat.com> | 2022-03-14 10:24:36 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-03-14 10:24:36 +0100 |
commit | a119e6ca70ffab14f0a70908fa3eeb83b41bb5ab (patch) | |
tree | 51b72774694f5e1aac0bb17fc1a5e528dbad9b44 /src/common/memory.hpp | |
parent | 6b5754655f78a7f93b756ff902ce9fd80d9dc4ec (diff) |
refactor: rename std to common
Diffstat (limited to 'src/common/memory.hpp')
-rw-r--r-- | src/common/memory.hpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/common/memory.hpp b/src/common/memory.hpp new file mode 100644 index 0000000..de72d80 --- /dev/null +++ b/src/common/memory.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include <stddef.h> + +namespace common +{ + +template <typename memType> +memType *malloc_s(unsigned int size); + +template <class Target> +class UniquePtr +{ +public: + explicit UniquePtr() = default; + explicit UniquePtr(Target *target); + + // Move constructor + UniquePtr(UniquePtr &&unique_ptr) noexcept; + + // Move assignment operator + UniquePtr &operator=(UniquePtr &&unique_ptr) noexcept; + + // Disable the copy constructor + UniquePtr(const UniquePtr &unique_ptr) = delete; + + // Disable the copy assignment operator + UniquePtr &operator=(const UniquePtr &unique_ptr) = delete; + + ~UniquePtr(); + + Target operator*() const; + Target *operator->() const; + +private: + Target *_target = nullptr; +}; + +template <typename Target, typename... Args> +UniquePtr<Target> make_unique(Args... args); + +} // namespace common + +#include "memory.tpp" |