Adds functions to take ownership from a unique ptr
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2022-05-14 15:32:10 +02:00
parent 64108448bc
commit 74ef6b5bdc
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 17 additions and 0 deletions

View File

@ -36,6 +36,13 @@ namespace ArbUt {
/// @brief Return whether the pointer is null or not.
[[nodiscard]] inline bool HasValue() const noexcept { return _raw != nullptr; }
/// @brief Get the raw underlying pointer, and take ownership of it. This removes the existing pointer in here.
inline T* nullable TakeOwnership() noexcept {
auto raw = _raw;
_raw = nullptr;
return raw;
}
/// @brief Get the raw underlying pointer.
inline T* nullable GetValue() const noexcept { return _raw; }

View File

@ -56,6 +56,16 @@ namespace ArbUt {
/// @warning Note that this asserts that the underlying pointer is not null first, to prevent segfaults.
inline T* non_null operator->() const noexcept { return _raw; }
/// @brief Get the raw underlying pointer, and take ownership of it. This removes the existing pointer in here.
#if defined(__clang__)
[[clang::no_sanitize("nullability-assign")]]
#endif
inline T* non_null
TakeOwnership() noexcept {
auto raw = _raw;
_raw = nullptr;
return raw;
}
/// @brief Get the raw underlying pointer.
inline T* non_null GetRaw() const noexcept { return _raw; }