diff options
-rw-r--r-- | compat/borrowed-ptr.hpp | 36 | ||||
-rw-r--r-- | compat/borrowed-ptr.inl | 5 |
2 files changed, 20 insertions, 21 deletions
diff --git a/compat/borrowed-ptr.hpp b/compat/borrowed-ptr.hpp index 7ab42ebb..c4cc7975 100644 --- a/compat/borrowed-ptr.hpp +++ b/compat/borrowed-ptr.hpp @@ -12,7 +12,17 @@ #define fm_bptr_assert(...) void() #endif -namespace floormat { struct bptr_base; } +namespace floormat { +struct bptr_base +{ + virtual ~bptr_base() noexcept; + bptr_base() noexcept; + bptr_base(const bptr_base&) noexcept; + bptr_base(bptr_base&&) noexcept; + bptr_base& operator=(const bptr_base&) noexcept; + bptr_base& operator=(bptr_base&&) noexcept; +}; +} // namespace floormat namespace floormat::detail_bptr { @@ -24,7 +34,6 @@ struct control_block final static void weak_decrement(control_block*& blk) noexcept; }; -#if 0 template<typename From, typename To> concept StaticCastable = requires(From* from, To* to) { static_cast<To*>(from); @@ -34,29 +43,13 @@ concept StaticCastable = requires(From* from, To* to) { template<typename From, typename To> 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&, To&>; }; -#else -template<typename From, typename To> concept DerivedFrom = true; -template<typename From, typename To> concept StaticCastable = true; -#endif } // namespace floormat::detail_bptr namespace floormat { -struct bptr_base -{ - virtual ~bptr_base() noexcept; - bptr_base() noexcept; - bptr_base(const bptr_base&) noexcept; - bptr_base(bptr_base&&) noexcept; - bptr_base& operator=(const bptr_base&) noexcept; - bptr_base& operator=(bptr_base&&) noexcept; -}; - template<typename T> class bptr final // NOLINT(*-special-member-functions) { @@ -69,7 +62,7 @@ class bptr final // NOLINT(*-special-member-functions) public: template<typename... Ts> - //requires std::is_constructible_v<std::remove_const_t<T>, Ts&&...> + requires std::is_constructible_v<std::remove_const_t<T>, Ts&&...> explicit bptr(InPlaceInitT, Ts&&... args) noexcept; template<detail_bptr::DerivedFrom<T> Y> explicit bptr(Y* ptr) noexcept; @@ -79,6 +72,9 @@ public: bptr(std::nullptr_t) noexcept; // NOLINT(*-explicit-conversions) bptr& operator=(std::nullptr_t) noexcept; + bptr(const bptr<std::remove_const_t<T>>& ptr) noexcept requires std::is_const_v<T>; + bptr(bptr<std::remove_const_t<T>>&& ptr) noexcept requires std::is_const_v<T>; + bptr(const bptr&) noexcept; bptr& operator=(const bptr&) noexcept; template<detail_bptr::DerivedFrom<T> Y> bptr(const bptr<Y>&) noexcept; diff --git a/compat/borrowed-ptr.inl b/compat/borrowed-ptr.inl index 327bd7cd..dfc112c7 100644 --- a/compat/borrowed-ptr.inl +++ b/compat/borrowed-ptr.inl @@ -11,7 +11,7 @@ namespace floormat { template<typename T> template<typename... Ts> -//requires std::is_constructible_v<std::remove_const_t<T>, 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)... } } {} @@ -26,6 +26,9 @@ bptr<T>::bptr(Y* ptr) noexcept: template<typename T> bptr<T>::~bptr() noexcept { if (blk) detail_bptr::control_block::decrement(blk); } +template<typename T> bptr<T>::bptr(const bptr<std::remove_const_t<T>>& ptr) noexcept requires std::is_const_v<T>: bptr{ptr, nullptr} {} +template<typename T> bptr<T>::bptr(bptr<std::remove_const_t<T>>&& ptr) noexcept requires std::is_const_v<T>: bptr{move(ptr), nullptr} {} + template<typename T> bptr<T>::bptr(const bptr& other) noexcept: bptr{other, nullptr} {} template<typename T> bptr<T>::bptr(bptr&& other) noexcept: bptr{move(other), nullptr} {} template<typename T> bptr<T>& bptr<T>::operator=(const bptr& other) noexcept { return _copy_assign(other); } |