From e591c604de6b0fdf6decd384e8c45996e48e187e Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Sat, 10 Dec 2022 19:37:52 +0330 Subject: [PATCH] AK: Add Optional-like value()/has_value() getters to WeakPtr --- AK/WeakPtr.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/AK/WeakPtr.h b/AK/WeakPtr.h index ad94755de9..730a85558d 100644 --- a/AK/WeakPtr.h +++ b/AK/WeakPtr.h @@ -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 take_link() { return move(m_link); }