27 lines
1.0 KiB
C++
27 lines
1.0 KiB
C++
#ifndef ARBUTILS_BORROWEDPTR_HPP
|
|
#define ARBUTILS_BORROWEDPTR_HPP
|
|
|
|
namespace Arbutils::Memory {
|
|
template <class T> class BorrowedPtr {
|
|
T* _ptr;
|
|
|
|
public:
|
|
inline BorrowedPtr() { _ptr = nullptr; };
|
|
inline explicit constexpr BorrowedPtr(T* ptr) noexcept : _ptr(ptr){};
|
|
|
|
inline constexpr T* GetUnsafe() noexcept { return _ptr; }
|
|
inline constexpr const T* GetUnsafe() const noexcept { return _ptr; }
|
|
inline constexpr bool IsNull() const noexcept { return _ptr == nullptr; }
|
|
|
|
T* operator->() noexcept { return _ptr; }
|
|
T* operator->() const noexcept { return _ptr; }
|
|
|
|
inline bool operator==(const BorrowedPtr& rhs) const noexcept { return _ptr == rhs._ptr; }
|
|
inline bool operator!=(const BorrowedPtr& rhs) const noexcept { return _ptr != rhs._ptr; }
|
|
inline bool operator==(const T* rhs) const noexcept { return _ptr == rhs; }
|
|
inline bool operator!=(const T* rhs) const noexcept { return _ptr != rhs; }
|
|
};
|
|
}
|
|
|
|
#endif // ARBUTILS_BORROWEDPTR_HPP
|