Allow borrowing as nonnull or optional pointers.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-03-30 17:58:11 +02:00
parent 9e2805f684
commit 16b082f00d
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 8 additions and 6 deletions

View File

@ -3,14 +3,14 @@
#include "../Assert.hpp"
#include "NonNullBorrowedPtr.hpp"
#include "OwnPtr.hpp"
#include "BorrowedPtr.hpp"
namespace Arbutils::Memory {
template <class T> class NonNullOwnPtr {
T* _ptr;
public:
inline NonNullOwnPtr() {};
inline NonNullOwnPtr(){};
inline NonNullOwnPtr(T* ptr) : _ptr(ptr) { AssertNotNull(ptr); };
NonNullOwnPtr<T>(const NonNullOwnPtr<T>&) = delete;
@ -21,10 +21,9 @@ namespace Arbutils::Memory {
inline constexpr const T* GetUnsafe() const noexcept { return _ptr; }
inline NonNullBorrowedPtr<T> Borrow() { return NonNullBorrowedPtr<T>(_ptr); }
inline const NonNullBorrowedPtr<const T> Borrow() const{
return NonNullBorrowedPtr<const T>(_ptr);
}
inline const NonNullBorrowedPtr<const T> Borrow() const { return NonNullBorrowedPtr<const T>(_ptr); }
inline BorrowedPtr<T> BorrowOptional() { return BorrowedPtr<T>(_ptr); }
inline const BorrowedPtr<const T> BorrowOptional() const { return BorrowedPtr<const T>(_ptr); }
T* operator->() noexcept { return _ptr; }
const T* operator->() const noexcept { return _ptr; }

View File

@ -3,6 +3,7 @@
#include <memory>
#include "BorrowedPtr.hpp"
#include "NonNullBorrowedPtr.hpp"
namespace Arbutils::Memory {
template <class T> class OwnPtr {
@ -22,6 +23,8 @@ namespace Arbutils::Memory {
inline BorrowedPtr<T> Borrow() { return BorrowedPtr<T>(_ptr); }
inline const BorrowedPtr<const T> Borrow() const { return BorrowedPtr<const T>(_ptr); }
inline BorrowedPtr<T> BorrowNonNull() { return NonNullBorrowedPtr<T>(_ptr); }
inline const BorrowedPtr<const T> BorrowNonNull() const { return NonNullBorrowedPtr<const T>(_ptr); }
T* operator->() noexcept { return _ptr; }
const T* operator->() const noexcept { return _ptr; }