From 96b2bd61ab08f4fb9055cec88141dcc28faefa1f Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Mon, 30 Mar 2020 17:41:08 +0200 Subject: [PATCH] Default the BorrowedPtr and OwnPtr to nullptr. --- src/Memory/BorrowedPtr.hpp | 2 +- src/Memory/NonNullBorrowedPtr.hpp | 6 ++---- src/Memory/OwnPtr.hpp | 15 ++++----------- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/Memory/BorrowedPtr.hpp b/src/Memory/BorrowedPtr.hpp index acf9b78..ddca6bb 100644 --- a/src/Memory/BorrowedPtr.hpp +++ b/src/Memory/BorrowedPtr.hpp @@ -6,7 +6,7 @@ namespace Arbutils::Memory { T* _ptr; public: - inline BorrowedPtr() {}; + inline BorrowedPtr() { _ptr = nullptr; }; inline explicit constexpr BorrowedPtr(T* ptr) noexcept : _ptr(ptr){}; inline constexpr T* GetUnsafe() noexcept { return _ptr; } diff --git a/src/Memory/NonNullBorrowedPtr.hpp b/src/Memory/NonNullBorrowedPtr.hpp index af03869..5261d17 100644 --- a/src/Memory/NonNullBorrowedPtr.hpp +++ b/src/Memory/NonNullBorrowedPtr.hpp @@ -9,10 +9,8 @@ namespace Arbutils::Memory { T* _ptr; public: - inline NonNullBorrowedPtr() {}; - inline explicit NonNullBorrowedPtr(T* ptr) : _ptr(ptr){ - AssertNotNull(ptr); - }; + inline NonNullBorrowedPtr(){}; + inline explicit NonNullBorrowedPtr(T* ptr) : _ptr(ptr) { AssertNotNull(ptr); }; inline constexpr T* GetUnsafe() noexcept { return _ptr; } inline constexpr const T* GetUnsafe() const noexcept { return _ptr; } diff --git a/src/Memory/OwnPtr.hpp b/src/Memory/OwnPtr.hpp index 777e395..f5ccaf3 100644 --- a/src/Memory/OwnPtr.hpp +++ b/src/Memory/OwnPtr.hpp @@ -9,7 +9,7 @@ namespace Arbutils::Memory { T* _ptr; public: - inline OwnPtr() {}; + inline OwnPtr() { _ptr = nullptr; }; inline explicit constexpr OwnPtr(T* ptr) noexcept : _ptr(ptr){}; OwnPtr(const OwnPtr&) = delete; @@ -18,16 +18,10 @@ namespace Arbutils::Memory { inline constexpr T* GetUnsafe() noexcept { return _ptr; } inline constexpr const T* GetUnsafe() const noexcept { return _ptr; } - inline constexpr const T* IsNull() const noexcept { - return _ptr == nullptr; - } + inline constexpr const T* IsNull() const noexcept { return _ptr == nullptr; } - inline BorrowedPtr Borrow(){ - return BorrowedPtr(_ptr); - } - inline const BorrowedPtr Borrow() const{ - return BorrowedPtr(_ptr); - } + inline BorrowedPtr Borrow() { return BorrowedPtr(_ptr); } + inline const BorrowedPtr Borrow() const { return BorrowedPtr(_ptr); } T* operator->() noexcept { return _ptr; } const T* operator->() const noexcept { return _ptr; } @@ -39,5 +33,4 @@ namespace Arbutils::Memory { }; } - #endif // ARBUTILS_OWNPTR_HPP