/* * Copyright (c) 2022-2023, MacDue * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include namespace AK { template struct ValueComparingNonnullRefPtr : public NonnullRefPtr { using NonnullRefPtr::NonnullRefPtr; ValueComparingNonnullRefPtr(NonnullRefPtr const& other) : NonnullRefPtr(other) { } ValueComparingNonnullRefPtr(NonnullRefPtr&& other) : NonnullRefPtr(move(other)) { } bool operator==(ValueComparingNonnullRefPtr const& other) const { return this->ptr() == other.ptr() || this->ptr()->equals(*other); } private: using NonnullRefPtr::operator==; }; template struct ValueComparingRefPtr : public RefPtr { using RefPtr::RefPtr; ValueComparingRefPtr(RefPtr const& other) : RefPtr(other) { } ValueComparingRefPtr(RefPtr&& other) : RefPtr(move(other)) { } template bool operator==(ValueComparingNonnullRefPtr const& other) const { return this->ptr() == other.ptr() || (this->ptr() && this->ptr()->equals(*other)); } bool operator==(ValueComparingRefPtr const& other) const { return this->ptr() == other.ptr() || (this->ptr() && other.ptr() && this->ptr()->equals(*other)); } bool operator==(nullptr_t) const { return this->is_null(); } private: using RefPtr::operator==; }; }