AK: Add Optional-like value()/has_value() getters to WeakPtr

This commit is contained in:
Ali Mohammad Pur 2022-12-10 19:37:52 +03:30 committed by Ali Mohammad Pur
parent c373c2deb0
commit e591c604de
Notes: sideshowbarker 2024-07-17 08:38:37 +09:00

View file

@ -149,9 +149,14 @@ public:
return nullptr;
}
[[nodiscard]] T const* value() const { return unsafe_ptr(); }
[[nodiscard]] T* value() { return unsafe_ptr(); }
operator bool() const { return m_link ? !m_link->is_null() : false; }
[[nodiscard]] bool is_null() const { return !m_link || m_link->is_null(); }
[[nodiscard]] bool has_value() const { return !is_null(); }
void clear() { m_link = nullptr; }
[[nodiscard]] RefPtr<WeakLink> take_link() { return move(m_link); }