#pragma once #include "borrowed-ptr-fwd.hpp" namespace floormat::detail_borrowed_ptr { struct control_block; template concept StaticCastable = requires(From* from) { static_cast(from); }; template concept DerivedFrom = requires(From* x) { !std::is_same_v; std::is_convertible_v; }; } // namespace floormat::detail_borrowed_ptr 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 requires std::is_convertible_v class bptr final // NOLINT(*-special-member-functions) { detail_borrowed_ptr::control_block* blk; template bptr(const bptr& other, std::nullptr_t) noexcept; template bptr& _copy_assign(const bptr& other) noexcept; template bptr(bptr&& other, std::nullptr_t) noexcept; template bptr& _move_assign(bptr&& other) noexcept; public: template requires std::is_constructible_v, Ts&&...> explicit bptr(InPlaceInitT, Ts&&... args) noexcept; explicit bptr(T* ptr) noexcept; bptr() noexcept; ~bptr() noexcept; bptr(std::nullptr_t) noexcept; // NOLINT(*-explicit-conversions) bptr& operator=(std::nullptr_t) noexcept; CORRADE_ALWAYS_INLINE bptr(const bptr&) noexcept; CORRADE_ALWAYS_INLINE bptr& operator=(const bptr&) noexcept; template Y> CORRADE_ALWAYS_INLINE bptr(const bptr&) noexcept; template Y> CORRADE_ALWAYS_INLINE bptr& operator=(const bptr&) noexcept; CORRADE_ALWAYS_INLINE bptr(bptr&&) noexcept; CORRADE_ALWAYS_INLINE bptr& operator=(bptr&&) noexcept; template Y> CORRADE_ALWAYS_INLINE bptr(bptr&&) noexcept; template Y> CORRADE_ALWAYS_INLINE bptr& operator=(bptr&&) noexcept; void reset() noexcept; void destroy() noexcept; void swap(bptr& other) noexcept; uint32_t use_count() const noexcept; T* get() const noexcept; T* operator->() const noexcept; T& operator*() const noexcept; explicit operator bool() const noexcept; bool operator==(const bptr>& other) const noexcept; bool operator==(const bptr>& other) const noexcept; template requires std::is_convertible_v friend class bptr; template requires (std::is_convertible_v && detail_borrowed_ptr::StaticCastable) friend bptr static_pointer_cast(const bptr& p) noexcept; }; template requires (std::is_convertible_v && detail_borrowed_ptr::StaticCastable) bptr static_pointer_cast(const bptr& p) noexcept { if (p.blk && p.blk->_ptr) [[likely]] return bptr{p, nullptr}; return bptr{nullptr}; } } // namespace floormat