diff --git a/src/Memory/BorrowedPtr.hpp b/src/Memory/BorrowedPtr.hpp index 3197214..600ca0f 100644 --- a/src/Memory/BorrowedPtr.hpp +++ b/src/Memory/BorrowedPtr.hpp @@ -2,6 +2,9 @@ #define ARBUTILS_BORROWEDPTR_HPP namespace Arbutils::Memory { + template + class NonNullBorrowedPtr; + template class BorrowedPtr { T* _ptr; @@ -13,6 +16,10 @@ namespace Arbutils::Memory { inline constexpr const T* GetUnsafe() const noexcept { return _ptr; } inline constexpr bool IsNull() const noexcept { return _ptr == nullptr; } + inline NonNullBorrowedPtr GetNonNull(){ + return NonNullBorrowedPtr(_ptr); + } + T* operator->() noexcept { return _ptr; } T* operator->() const noexcept { return _ptr; } diff --git a/src/Memory/NonNullBorrowedPtr.hpp b/src/Memory/NonNullBorrowedPtr.hpp index d075ec3..5b94f80 100644 --- a/src/Memory/NonNullBorrowedPtr.hpp +++ b/src/Memory/NonNullBorrowedPtr.hpp @@ -4,6 +4,9 @@ #include "BorrowedPtr.hpp" namespace Arbutils::Memory { + template + class BorrowedPtr; + template class NonNullBorrowedPtr { private: T* _ptr; @@ -15,6 +18,10 @@ namespace Arbutils::Memory { inline constexpr T* GetUnsafe() noexcept { return _ptr; } inline constexpr const T* GetUnsafe() const noexcept { return _ptr; } + inline BorrowedPtr GetOptional(){ + return BorrowedPtr(_ptr); + } + T* operator->() noexcept { return _ptr; } T* operator->() const noexcept { return _ptr; }