Assert BorrowedPtr is not null when trying to dereference it.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-06-26 13:12:58 +02:00
parent f59ec6c957
commit d547046752
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
1 changed files with 6 additions and 4 deletions

View File

@ -2,6 +2,7 @@
#define ARBUTILS_BORROWEDPTR_HPP
#include <memory>
#include "../Assert.hpp"
namespace ArbUt {
/// A borrowed pointer is used to indicate a pointer that is not owned by an object, but instead borrowed from
@ -24,7 +25,10 @@ namespace ArbUt {
return *this;
}
inline T* operator->() const noexcept { return _raw; }
inline T* operator->() const noexcept {
AssertNotNull(_raw);
return _raw;
}
inline T* GetRaw() const noexcept { return _raw; }
inline bool operator==(const BorrowedPtr& rhs) const noexcept { return _raw == rhs._raw; }
@ -32,9 +36,7 @@ namespace ArbUt {
[[nodiscard]] inline constexpr bool IsNull() const noexcept { return _raw == nullptr; }
inline BorrowedPtr<const T> Const() const noexcept {
return BorrowedPtr<const T>(_raw);
}
inline BorrowedPtr<const T> Const() const noexcept { return BorrowedPtr<const T>(_raw); }
template <class TCast> inline BorrowedPtr<TCast> As() const {
auto cast = dynamic_cast<TCast*>(_raw);