summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-07-16 07:50:56 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-07-16 07:50:56 +0200
commite8ba17588d7ba8d047b32bd3aca1aee501512342 (patch)
tree4e6bbdb88c6f7b35b3d3237e79068f3e1122d554
parente88f946e5b88373315b551a336584e5c273d8b0b (diff)
w
-rw-r--r--compat/borrowed-ptr.hpp1
-rw-r--r--compat/borrowed-ptr.inl11
2 files changed, 11 insertions, 1 deletions
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<detail_bptr::DerivedFrom<T> Y> bptr& operator=(bptr<Y>&&) noexcept;
void reset() noexcept;
+ template<detail_bptr::DerivedFrom<T> 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
@@ -70,6 +70,15 @@ bptr<T>& bptr<T>::operator=(bptr<Y>&& other) noexcept
template<typename T> void bptr<T>::reset() noexcept { if (blk) blk->decrement(blk); }
template<typename T>
+template<detail_bptr::DerivedFrom<T> Y>
+void bptr<T>::reset(Y* ptr) noexcept
+{
+ if (blk)
+ blk->decrement(blk);
+ blk = ptr ? new detail_bptr::control_block{const_cast<std::remove_const_t<Y>*>(ptr), 1} : nullptr;
+}
+
+template<typename T>
void bptr<T>::destroy() noexcept
{
if (!blk)
@@ -150,7 +159,7 @@ template<typename T> bool bptr<T>::operator==(const std::nullptr_t&) const noexc
template<typename T> std::strong_ordering bptr<T>::operator<=>(const bptr<const std::remove_const_t<T>>& other) const noexcept { return get() <=> other.get(); }
template<typename T> std::strong_ordering bptr<T>::operator<=>(const bptr<std::remove_const_t<T>>& other) const noexcept { return get() <=> other.get(); }
-template<typename T> std::strong_ordering bptr<T>::operator<=>(const std::nullptr_t&) const noexcept { return get() <=> nullptr; }
+template<typename T> std::strong_ordering bptr<T>::operator<=>(const std::nullptr_t&) const noexcept { return get() <=> (T*)nullptr; }
template<typename T> void bptr<T>::swap(bptr& other) noexcept { floormat::swap(blk, other.blk); }