summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--compat/borrowed-ptr.hpp24
-rw-r--r--compat/borrowed-ptr.inl10
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<typename From, typename To>
-concept StaticCastable = requires(From* from) {
+concept StaticCastable = requires(From* from, To* to) {
static_cast<To*>(from);
- requires std::is_base_of_v<std::remove_cvref_t<From>, std::remove_cvref_t<To>>;
+ static_cast<const bptr_base*>(from);
+ static_cast<const bptr_base*>(to);
};
template<typename From, typename To>
-concept DerivedFrom = requires(From* x) {
-#if 0
+concept DerivedFrom = requires(From* from, To* to) {
+ static_cast<const bptr_base*>(from);
+ static_cast<const bptr_base*>(to);
requires std::is_convertible_v<From*, To*>;
- requires std::is_convertible_v<From*, const bptr_base*>;
- requires std::is_convertible_v<To*, const bptr_base*>;
- requires std::is_base_of_v<bptr_base, From>;
- requires std::is_base_of_v<bptr_base, To>;
- requires std::is_base_of_v<std::remove_cvref_t<To>, std::remove_cvref_t<From>>;
+};
#else
- static_cast<To*>(std::declval<From*>());
+template<typename From, typename To> concept DerivedFrom = true;
+template<typename From, typename To> concept StaticCastable = true;
#endif
-};
} // namespace floormat::detail_bptr
@@ -103,6 +102,9 @@ public:
explicit operator bool() const noexcept;
bool operator==(const bptr<const T>& other) const noexcept;
+ bool operator==(const bptr<T>& other) const noexcept requires (!std::is_const_v<T>);
+ bool operator==(const std::nullptr_t& other) const noexcept;
+
std::strong_ordering operator<=>(const bptr<const T>& other) const noexcept;
template<typename U> 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<typename T> T& bptr<T>::operator*() const noexcept { return *operator->
template<typename T> bptr<T>::operator bool() const noexcept { return blk && blk->_ptr; }
-template<typename T>
-bool bptr<T>::operator==(const bptr<const T>& other) const noexcept
+template<typename T> bool bptr<T>::operator==(const bptr<const T>& other) const noexcept
{
- return !blk == !other.blk && blk->_ptr == other.blk->_ptr;
+ return blk ? (other.blk && blk->_ptr == other.blk->_ptr) : !other.blk;
+}
+template<typename T> bool bptr<T>::operator==(const bptr<T>& other) const noexcept requires (!std::is_const_v<T>) {
+ return blk ? (other.blk && blk->_ptr == other.blk->_ptr) : !other.blk;
}
+template<typename T> bool bptr<T>::operator==(const std::nullptr_t&) const noexcept { return !blk || !blk->_ptr; }
+
template<typename T>
std::strong_ordering bptr<T>::operator<=>(const bptr<const T>& other) const noexcept
{