From 8d1cd579d443890b7ae6af87229d6e73856ee73a Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 15 Jul 2024 12:56:34 +0200 Subject: w --- compat/borrowed-ptr.cpp | 1 - compat/borrowed-ptr.hpp | 15 ++++++++++++++- compat/borrowed-ptr.inl | 20 ++++++++------------ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/compat/borrowed-ptr.cpp b/compat/borrowed-ptr.cpp index 04919df0..f6f098fa 100644 --- a/compat/borrowed-ptr.cpp +++ b/compat/borrowed-ptr.cpp @@ -1,5 +1,4 @@ #include "borrowed-ptr.inl" -#include "compat/assert.hpp" namespace floormat::detail_bptr { diff --git a/compat/borrowed-ptr.hpp b/compat/borrowed-ptr.hpp index 65115f94..4da792d1 100644 --- a/compat/borrowed-ptr.hpp +++ b/compat/borrowed-ptr.hpp @@ -1,9 +1,17 @@ #pragma once #include "borrowed-ptr-fwd.hpp" +#include + +namespace floormat { struct bptr_base; } namespace floormat::detail_bptr { -struct control_block; +struct control_block final +{ + bptr_base* _ptr; + uint32_t _count; + static void decrement(control_block*& blk) noexcept; +}; template concept StaticCastable = requires(From* from) { @@ -72,10 +80,15 @@ public: T& operator*() const noexcept; explicit operator bool() const noexcept; + bool operator==(const bptr>& other) const noexcept; bool operator==(const bptr>& other) const noexcept; bool operator==(const std::nullptr_t& other) const noexcept; + std::strong_ordering operator<=>(const bptr>& other) const noexcept; + std::strong_ordering operator<=>(const bptr>& other) const noexcept; + std::strong_ordering operator<=>(const std::nullptr_t& other) const noexcept; + template friend class bptr; template diff --git a/compat/borrowed-ptr.inl b/compat/borrowed-ptr.inl index 59b4e14a..4d03545d 100644 --- a/compat/borrowed-ptr.inl +++ b/compat/borrowed-ptr.inl @@ -20,24 +20,13 @@ #endif #endif -namespace floormat::detail_bptr { - -struct control_block final -{ - bptr_base* _ptr; - uint32_t _count; - static void decrement(control_block*& blk) noexcept; -}; - -} // namespace floormat::detail_bptr - namespace floormat { template template requires std::is_constructible_v, Ts&&...> bptr::bptr(InPlaceInitT, Ts&&... args) noexcept: - bptr{ new std::remove_const_t{ forward(args)... } } + bptr{ new std::remove_const_t{ forward(args)... } } {} template bptr::bptr(std::nullptr_t) noexcept: blk{nullptr} {} @@ -152,10 +141,17 @@ T* bptr::operator->() const noexcept } template T& bptr::operator*() const noexcept { return *operator->(); } + template bptr::operator bool() const noexcept { return blk && blk->_ptr; } + template bool bptr::operator==(const bptr>& other) const noexcept { return get() == other.get(); } template bool bptr::operator==(const bptr>& other) const noexcept { return get() == other.get(); } template bool bptr::operator==(const std::nullptr_t&) const noexcept { return !blk || !blk->_ptr; } + +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 void bptr::swap(bptr& other) noexcept { floormat::swap(blk, other.blk); } template -- cgit v1.2.3