From 6aabc74a535da1f2d5cf866346b31939d097cbac Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 16 Jul 2024 12:23:50 +0200 Subject: w --- compat/borrowed-ptr.hpp | 24 +++++++++++++----------- compat/borrowed-ptr.inl | 10 +++++++--- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/compat/borrowed-ptr.hpp b/compat/borrowed-ptr.hpp index 62394087..7ab42ebb 100644 --- a/compat/borrowed-ptr.hpp +++ b/compat/borrowed-ptr.hpp @@ -24,25 +24,24 @@ struct control_block final static void weak_decrement(control_block*& blk) noexcept; }; +#if 0 template -concept StaticCastable = requires(From* from) { +concept StaticCastable = requires(From* from, To* to) { static_cast(from); - requires std::is_base_of_v, std::remove_cvref_t>; + static_cast(from); + static_cast(to); }; template -concept DerivedFrom = requires(From* x) { -#if 0 +concept DerivedFrom = requires(From* from, To* to) { + static_cast(from); + static_cast(to); requires std::is_convertible_v; - requires std::is_convertible_v; - requires std::is_convertible_v; - requires std::is_base_of_v; - requires std::is_base_of_v; - requires std::is_base_of_v, std::remove_cvref_t>; +}; #else - static_cast(std::declval()); +template concept DerivedFrom = true; +template concept StaticCastable = true; #endif -}; } // namespace floormat::detail_bptr @@ -103,6 +102,9 @@ public: explicit operator bool() const noexcept; bool operator==(const bptr& other) const noexcept; + bool operator==(const bptr& other) const noexcept requires (!std::is_const_v); + bool operator==(const std::nullptr_t& other) const noexcept; + std::strong_ordering operator<=>(const bptr& other) const noexcept; template friend class bptr; diff --git a/compat/borrowed-ptr.inl b/compat/borrowed-ptr.inl index 2ffd1e92..327bd7cd 100644 --- a/compat/borrowed-ptr.inl +++ b/compat/borrowed-ptr.inl @@ -145,12 +145,16 @@ 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 +template bool bptr::operator==(const bptr& other) const noexcept { - return !blk == !other.blk && blk->_ptr == other.blk->_ptr; + return blk ? (other.blk && blk->_ptr == other.blk->_ptr) : !other.blk; +} +template bool bptr::operator==(const bptr& other) const noexcept requires (!std::is_const_v) { + return blk ? (other.blk && blk->_ptr == other.blk->_ptr) : !other.blk; } +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 { -- cgit v1.2.3