summaryrefslogtreecommitdiffhomepage
path: root/compat/safe-ptr.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'compat/safe-ptr.hpp')
-rw-r--r--compat/safe-ptr.hpp35
1 files changed, 11 insertions, 24 deletions
diff --git a/compat/safe-ptr.hpp b/compat/safe-ptr.hpp
index 0882f3be..95cd3bae 100644
--- a/compat/safe-ptr.hpp
+++ b/compat/safe-ptr.hpp
@@ -13,41 +13,26 @@ class safe_ptr final
T* ptr;
public:
- template<typename... Ts>
- requires requires (Ts&&... xs) {
- new T{Utility::forward<Ts>(xs)...};
- }
- safe_ptr(InPlaceInitT, Ts&&... args) noexcept:
- ptr{new T{Utility::forward<Ts>(args)...}}
- {}
-
- explicit safe_ptr(T*&& ptr) noexcept: ptr{ptr}
- {
- fm_assert(ptr != nullptr);
- ptr = nullptr;
- }
-
~safe_ptr() noexcept
{
- if (ptr) [[likely]]
- delete ptr;
+ delete ptr;
ptr = (T*)0xbadcafedeadbabe;
}
- explicit safe_ptr(safe_ptr&& other) noexcept: ptr{other.ptr}
- {
- other.ptr = nullptr;
- }
+ safe_ptr(std::nullptr_t) = delete;
+ safe_ptr(T* ptr) noexcept: ptr{ptr} { fm_assert(ptr != nullptr); }
+ safe_ptr(safe_ptr&& other) noexcept: ptr{other.ptr} { other.ptr = nullptr; }
+
+ safe_ptr() noexcept: safe_ptr{InPlaceInit} {}
- explicit safe_ptr() noexcept:
- ptr{new T{}}
+ template<typename... Ts> safe_ptr(InPlaceInitT, Ts&&... args) noexcept:
+ ptr(new T{ Utility::forward<Ts>(args)... })
{}
safe_ptr& operator=(safe_ptr&& other) noexcept
{
fm_assert(this != &other);
- if (ptr) [[likely]]
- delete ptr;
+ delete ptr;
ptr = other.ptr;
other.ptr = nullptr;
return *this;
@@ -57,6 +42,8 @@ public:
//explicit operator bool() const noexcept { return ptr != nullptr; }
+ T* get() noexcept { return ptr; }
+ const T* get() const noexcept { return ptr; }
const T& operator*() const noexcept { return *ptr; }
T& operator*() noexcept { return *ptr; }
const T* operator->() const noexcept { return ptr; }