From 4c276b1b1b946e4b08eb7b92a24d30bdc55106fd Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 4 May 2024 12:56:21 +0200 Subject: wip bptr --- compat/borrowed-ptr.hpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 compat/borrowed-ptr.hpp (limited to 'compat/borrowed-ptr.hpp') diff --git a/compat/borrowed-ptr.hpp b/compat/borrowed-ptr.hpp new file mode 100644 index 00000000..f649cae3 --- /dev/null +++ b/compat/borrowed-ptr.hpp @@ -0,0 +1,49 @@ +#pragma once + +namespace floormat::detail_borrowed_ptr { +struct control_block_; +} // namespace floormat::detail_borrowed_ptr + +namespace floormat { +template class bptr; +template bptr static_pointer_cast(const bptr& p); + +template +class bptr final // NOLINT(*-special-member-functions) +{ + T* ptr; // todo add simple_bptr that doesn't allow casting. should only have the control block element. + detail_borrowed_ptr::control_block_* blk; + + friend bptr static_pointer_cast(const bptr& p); + +public: + template + requires std::is_constructible_v + explicit bptr(InPlaceInitT, Ts&&... args) noexcept; + + constexpr bptr(std::nullptr_t) noexcept; // NOLINT(*-explicit-conversions) + constexpr bptr() noexcept; + explicit bptr(T* ptr) noexcept; + ~bptr() noexcept; + + template requires std::is_convertible_v bptr(const bptr&) noexcept; + template requires std::is_convertible_v bptr(bptr&&) noexcept; + template requires std::is_convertible_v bptr& operator=(const bptr&) noexcept; + template requires std::is_convertible_v bptr& operator=(bptr&&) noexcept; + + void swap() noexcept; + T* get() noexcept; + const T* get() const noexcept; + T& operator*() const noexcept; + T* operator->() const noexcept; + uint32_t use_count() const noexcept; + explicit operator bool() const noexcept; +}; + +template constexpr bptr::bptr(std::nullptr_t) noexcept: ptr{nullptr}, blk{nullptr} {} +template constexpr bptr::bptr() noexcept: bptr{nullptr} {} + + +template bptr(T* ptr) -> bptr; + +} // namespace floormat -- cgit v1.2.3