| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- module;
- export module Core.UniquePointer;
- export namespace Core {
- template<typename T>
- class UniquePointer final {
- T* t;
- public:
- UniquePointer(T* t_) : t(t_) {
- }
- UniquePointer() : UniquePointer(nullptr) {
- }
- ~UniquePointer() {
- delete t;
- }
- UniquePointer(const UniquePointer&) = delete;
- UniquePointer& operator=(const UniquePointer&) = delete;
- UniquePointer(UniquePointer&& other) noexcept : UniquePointer(other.t) {
- other.t = nullptr;
- }
- UniquePointer& operator=(UniquePointer&& other) noexcept {
- if(this != &other) {
- delete t;
- t = other.t;
- other.t = nullptr;
- }
- return *this;
- }
- T* operator->() {
- return t;
- }
- const T* operator->() const {
- return t;
- }
- operator T*() {
- return t;
- }
- operator const T*() const {
- return t;
- }
- };
- }
|