123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #ifndef CORE_UNIQUE_POINTER_HPP
- #define CORE_UNIQUE_POINTER_HPP
- 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) : UniquePointer(other.t) {
- other.t = nullptr;
- }
- UniquePointer& operator=(UniquePointer&& other) {
- 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;
- }
- };
- }
- #endif
|