/* * Copyright (c) 2025, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include namespace GC { template Weak::Weak(T const* ptr) : m_impl(ptr ? *ptr->heap().create_weak_impl(const_cast(static_cast(ptr))) : WeakImpl::the_null_weak_impl) { } template Weak::Weak(T const& ptr) : m_impl(*ptr.heap().create_weak_impl(const_cast(static_cast(&ptr)))) { } template template Weak::Weak(Weak const& other) requires(IsConvertible) : m_impl(other.impl()) { } template Weak::Weak(Ref const& other) : m_impl(*other.ptr()->heap().create_weak_impl(other.ptr())) { } template template Weak::Weak(Ref const& other) requires(IsConvertible) : m_impl(*other.ptr()->heap().create_weak_impl(other.ptr())) { } template template Weak& Weak::operator=(U const& other) requires(IsConvertible) { if (ptr() != other) { m_impl = *other.heap().create_weak_impl(const_cast(static_cast(&other))); } return *this; } template Weak& Weak::operator=(Ref const& other) { if (ptr() != other.ptr()) { m_impl = *other.ptr()->heap().create_weak_impl(other.ptr()); } return *this; } template template Weak& Weak::operator=(Ref const& other) requires(IsConvertible) { if (ptr() != other.ptr()) { m_impl = *other.ptr()->heap().create_weak_impl(other.ptr()); } return *this; } template Weak& Weak::operator=(T const& other) { if (ptr() != &other) { m_impl = *other.heap().create_weak_impl(const_cast(static_cast(&other))); } return *this; } template Weak& Weak::operator=(T const* other) { if (ptr() != other) { if (other) m_impl = *other->heap().create_weak_impl(const_cast(static_cast(other))); else m_impl = WeakImpl::the_null_weak_impl; } return *this; } template template Weak& Weak::operator=(U const* other) requires(IsConvertible) { if (ptr() != other) { if (other) m_impl = *other->heap().create_weak_impl(const_cast(static_cast(other))); else m_impl = WeakImpl::the_null_weak_impl; } return *this; } }