diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-07-15 12:56:34 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-07-15 12:56:34 +0200 |
commit | 8d1cd579d443890b7ae6af87229d6e73856ee73a (patch) | |
tree | 2251a90c8b28d51ca43bf8af1005977f17338069 | |
parent | e006e1487776c44d13c2828eae0573ed0aa86bd9 (diff) |
w
-rw-r--r-- | compat/borrowed-ptr.cpp | 1 | ||||
-rw-r--r-- | compat/borrowed-ptr.hpp | 15 | ||||
-rw-r--r-- | 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 <compare> + +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<typename From, typename To> concept StaticCastable = requires(From* from) { @@ -72,10 +80,15 @@ public: T& operator*() const noexcept; explicit operator bool() const noexcept; + bool operator==(const bptr<const std::remove_const_t<T>>& other) const noexcept; bool operator==(const bptr<std::remove_const_t<T>>& other) const noexcept; bool operator==(const std::nullptr_t& other) const noexcept; + std::strong_ordering operator<=>(const bptr<const std::remove_const_t<T>>& other) const noexcept; + std::strong_ordering operator<=>(const bptr<std::remove_const_t<T>>& other) const noexcept; + std::strong_ordering operator<=>(const std::nullptr_t& other) const noexcept; + template<typename U> friend class bptr; template<typename To, typename From> 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<typename T> template<typename... Ts> requires std::is_constructible_v<std::remove_const_t<T>, Ts&&...> bptr<T>::bptr(InPlaceInitT, Ts&&... args) noexcept: - bptr{ new std::remove_const_t<T>{ forward<Ts...>(args)... } } + bptr{ new std::remove_const_t<T>{ forward<Ts>(args)... } } {} template<typename T> bptr<T>::bptr(std::nullptr_t) noexcept: blk{nullptr} {} @@ -152,10 +141,17 @@ T* bptr<T>::operator->() const noexcept } 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 std::remove_const_t<T>>& other) const noexcept { return get() == other.get(); } template<typename T> bool bptr<T>::operator==(const bptr<std::remove_const_t<T>>& other) const noexcept { return get() == other.get(); } 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 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> void bptr<T>::swap(bptr& other) noexcept { floormat::swap(blk, other.blk); } template<typename T> |