Allow borrowing as nonnull or optional pointers.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
9e2805f684
commit
16b082f00d
|
@ -3,14 +3,14 @@
|
||||||
|
|
||||||
#include "../Assert.hpp"
|
#include "../Assert.hpp"
|
||||||
#include "NonNullBorrowedPtr.hpp"
|
#include "NonNullBorrowedPtr.hpp"
|
||||||
#include "OwnPtr.hpp"
|
#include "BorrowedPtr.hpp"
|
||||||
|
|
||||||
namespace Arbutils::Memory {
|
namespace Arbutils::Memory {
|
||||||
template <class T> class NonNullOwnPtr {
|
template <class T> class NonNullOwnPtr {
|
||||||
T* _ptr;
|
T* _ptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline NonNullOwnPtr() {};
|
inline NonNullOwnPtr(){};
|
||||||
inline NonNullOwnPtr(T* ptr) : _ptr(ptr) { AssertNotNull(ptr); };
|
inline NonNullOwnPtr(T* ptr) : _ptr(ptr) { AssertNotNull(ptr); };
|
||||||
|
|
||||||
NonNullOwnPtr<T>(const NonNullOwnPtr<T>&) = delete;
|
NonNullOwnPtr<T>(const NonNullOwnPtr<T>&) = delete;
|
||||||
|
@ -21,10 +21,9 @@ namespace Arbutils::Memory {
|
||||||
inline constexpr const T* GetUnsafe() const noexcept { return _ptr; }
|
inline constexpr const T* GetUnsafe() const noexcept { return _ptr; }
|
||||||
|
|
||||||
inline NonNullBorrowedPtr<T> Borrow() { return NonNullBorrowedPtr<T>(_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{
|
inline BorrowedPtr<T> BorrowOptional() { return BorrowedPtr<T>(_ptr); }
|
||||||
return NonNullBorrowedPtr<const T>(_ptr);
|
inline const BorrowedPtr<const T> BorrowOptional() const { return BorrowedPtr<const T>(_ptr); }
|
||||||
}
|
|
||||||
|
|
||||||
T* operator->() noexcept { return _ptr; }
|
T* operator->() noexcept { return _ptr; }
|
||||||
const T* operator->() const noexcept { return _ptr; }
|
const T* operator->() const noexcept { return _ptr; }
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "BorrowedPtr.hpp"
|
#include "BorrowedPtr.hpp"
|
||||||
|
#include "NonNullBorrowedPtr.hpp"
|
||||||
|
|
||||||
namespace Arbutils::Memory {
|
namespace Arbutils::Memory {
|
||||||
template <class T> class OwnPtr {
|
template <class T> class OwnPtr {
|
||||||
|
@ -22,6 +23,8 @@ namespace Arbutils::Memory {
|
||||||
|
|
||||||
inline BorrowedPtr<T> Borrow() { return BorrowedPtr<T>(_ptr); }
|
inline BorrowedPtr<T> Borrow() { return BorrowedPtr<T>(_ptr); }
|
||||||
inline const BorrowedPtr<const T> Borrow() const { return BorrowedPtr<const 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; }
|
T* operator->() noexcept { return _ptr; }
|
||||||
const T* operator->() const noexcept { return _ptr; }
|
const T* operator->() const noexcept { return _ptr; }
|
||||||
|
|
Loading…
Reference in New Issue