Allow transferring borrowedPtr into NonNull variant and vice versa.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-03-30 18:52:08 +02:00
parent f8b4d79e28
commit 4c1ca2e822
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 14 additions and 0 deletions

View File

@ -2,6 +2,9 @@
#define ARBUTILS_BORROWEDPTR_HPP #define ARBUTILS_BORROWEDPTR_HPP
namespace Arbutils::Memory { namespace Arbutils::Memory {
template <class>
class NonNullBorrowedPtr;
template <class T> class BorrowedPtr { template <class T> class BorrowedPtr {
T* _ptr; T* _ptr;
@ -13,6 +16,10 @@ namespace Arbutils::Memory {
inline constexpr const T* GetUnsafe() const noexcept { return _ptr; } inline constexpr const T* GetUnsafe() const noexcept { return _ptr; }
inline constexpr bool IsNull() const noexcept { return _ptr == nullptr; } inline constexpr bool IsNull() const noexcept { return _ptr == nullptr; }
inline NonNullBorrowedPtr<T> GetNonNull(){
return NonNullBorrowedPtr<T>(_ptr);
}
T* operator->() noexcept { return _ptr; } T* operator->() noexcept { return _ptr; }
T* operator->() const noexcept { return _ptr; } T* operator->() const noexcept { return _ptr; }

View File

@ -4,6 +4,9 @@
#include "BorrowedPtr.hpp" #include "BorrowedPtr.hpp"
namespace Arbutils::Memory { namespace Arbutils::Memory {
template <class>
class BorrowedPtr;
template <class T> class NonNullBorrowedPtr { template <class T> class NonNullBorrowedPtr {
private: private:
T* _ptr; T* _ptr;
@ -15,6 +18,10 @@ namespace Arbutils::Memory {
inline constexpr T* GetUnsafe() noexcept { return _ptr; } inline constexpr T* GetUnsafe() noexcept { return _ptr; }
inline constexpr const T* GetUnsafe() const noexcept { return _ptr; } inline constexpr const T* GetUnsafe() const noexcept { return _ptr; }
inline BorrowedPtr<T> GetOptional(){
return BorrowedPtr<T>(_ptr);
}
T* operator->() noexcept { return _ptr; } T* operator->() noexcept { return _ptr; }
T* operator->() const noexcept { return _ptr; } T* operator->() const noexcept { return _ptr; }