Allow transferring borrowedPtr into NonNull variant and vice versa.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
f8b4d79e28
commit
4c1ca2e822
|
@ -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; }
|
||||||
|
|
||||||
|
|
|
@ -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; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue