From e8ba17588d7ba8d047b32bd3aca1aee501512342 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 16 Jul 2024 07:50:56 +0200 Subject: w --- compat/borrowed-ptr.hpp | 1 + compat/borrowed-ptr.inl | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/compat/borrowed-ptr.hpp b/compat/borrowed-ptr.hpp index 4da792d1..92c1f761 100644 --- a/compat/borrowed-ptr.hpp +++ b/compat/borrowed-ptr.hpp @@ -71,6 +71,7 @@ public: template Y> bptr& operator=(bptr&&) noexcept; void reset() noexcept; + template Y> void reset(Y* ptr) noexcept; void destroy() noexcept; void swap(bptr& other) noexcept; uint32_t use_count() const noexcept; diff --git a/compat/borrowed-ptr.inl b/compat/borrowed-ptr.inl index 4d03545d..0abdea8f 100644 --- a/compat/borrowed-ptr.inl +++ b/compat/borrowed-ptr.inl @@ -69,6 +69,15 @@ bptr& bptr::operator=(bptr&& other) noexcept template void bptr::reset() noexcept { if (blk) blk->decrement(blk); } +template +template Y> +void bptr::reset(Y* ptr) noexcept +{ + if (blk) + blk->decrement(blk); + blk = ptr ? new detail_bptr::control_block{const_cast*>(ptr), 1} : nullptr; +} + template void bptr::destroy() noexcept { @@ -150,7 +159,7 @@ template bool bptr::operator==(const std::nullptr_t&) const noexc template std::strong_ordering bptr::operator<=>(const bptr>& other) const noexcept { return get() <=> other.get(); } template std::strong_ordering bptr::operator<=>(const bptr>& other) const noexcept { return get() <=> other.get(); } -template std::strong_ordering bptr::operator<=>(const std::nullptr_t&) const noexcept { return get() <=> nullptr; } +template std::strong_ordering bptr::operator<=>(const std::nullptr_t&) const noexcept { return get() <=> (T*)nullptr; } template void bptr::swap(bptr& other) noexcept { floormat::swap(blk, other.blk); } -- cgit v1.2.3