35 lines
953 B
C++
35 lines
953 B
C++
|
#ifndef ARBUTILS_NONNULLOWNPTR_HPP
|
||
|
#define ARBUTILS_NONNULLOWNPTR_HPP
|
||
|
|
||
|
#include "OwnPtr.hpp"
|
||
|
#include "../Assert.hpp"
|
||
|
#include "NonNullBorrowedPtr.hpp"
|
||
|
|
||
|
namespace Arbutils::Memory {
|
||
|
template <class T> class NonNullOwnPtr{
|
||
|
T* _ptr;
|
||
|
|
||
|
public:
|
||
|
inline explicit NonNullOwnPtr(T* ptr) : _ptr(ptr){
|
||
|
AssertNotNull(ptr);
|
||
|
};
|
||
|
|
||
|
NonNullOwnPtr<T>(const NonNullOwnPtr<T>&) = delete;
|
||
|
NonNullOwnPtr<T>& operator=(OwnPtr<T> const&) = delete;
|
||
|
|
||
|
inline ~NonNullOwnPtr() noexcept { delete _ptr; }
|
||
|
|
||
|
inline constexpr T* GetUnsafe() noexcept { return _ptr; }
|
||
|
inline constexpr const T* GetUnsafe() const noexcept { return _ptr; }
|
||
|
|
||
|
inline NonNullBorrowedPtr<T> Borrow(){
|
||
|
return NonNullBorrowedPtr<T>(_ptr);
|
||
|
}
|
||
|
|
||
|
T* operator->() noexcept { return _ptr; }
|
||
|
const T* operator->() const noexcept { return _ptr; }
|
||
|
};
|
||
|
}
|
||
|
|
||
|
#endif // ARBUTILS_NONNULLOWNPTR_HPP
|