diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-07-16 10:52:09 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-07-16 11:34:06 +0200 |
commit | eba565a6359957a7ba5c3af645af36eefd58fbf3 (patch) | |
tree | b0af5bb6d07dac275b6b91a91ddf74c074a15f91 /compat/weak-borrowed-ptr.hpp | |
parent | e8ba17588d7ba8d047b32bd3aca1aee501512342 (diff) |
w
Diffstat (limited to 'compat/weak-borrowed-ptr.hpp')
-rw-r--r-- | compat/weak-borrowed-ptr.hpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/compat/weak-borrowed-ptr.hpp b/compat/weak-borrowed-ptr.hpp new file mode 100644 index 00000000..ac512c5c --- /dev/null +++ b/compat/weak-borrowed-ptr.hpp @@ -0,0 +1,45 @@ +#pragma once +#include "borrowed-ptr.hpp" + +namespace floormat { + +template<typename T> +class weak_bptr final +{ + detail_bptr::control_block* blk; + + static detail_bptr::control_block* _copy(detail_bptr::control_block* ptr); + weak_bptr& _copy_assign(detail_bptr::control_block* other) noexcept; + weak_bptr& _move_assign(detail_bptr::control_block*& other) noexcept; + +public: + weak_bptr(std::nullptr_t) noexcept; + weak_bptr& operator=(std::nullptr_t) noexcept; + weak_bptr() noexcept; + ~weak_bptr() noexcept; + + template<detail_bptr::DerivedFrom<T> Y> weak_bptr(const bptr<Y>& ptr) noexcept; + template<detail_bptr::DerivedFrom<T> Y> weak_bptr(const weak_bptr<Y>& ptr) noexcept; + weak_bptr(const weak_bptr& ptr) noexcept; + + template<detail_bptr::DerivedFrom<T> Y> weak_bptr& operator=(const bptr<Y>& ptr) noexcept; + template<detail_bptr::DerivedFrom<T> Y> weak_bptr& operator=(const weak_bptr<Y>& ptr) noexcept; + weak_bptr& operator=(const weak_bptr& ptr) noexcept; + + template<detail_bptr::DerivedFrom<T> Y> weak_bptr(weak_bptr<Y>&& ptr) noexcept; + weak_bptr(weak_bptr&& ptr) noexcept; + + template<detail_bptr::DerivedFrom<T> Y> weak_bptr& operator=(weak_bptr<Y>&& ptr) noexcept; + weak_bptr& operator=(weak_bptr&& ptr) noexcept; + + void reset() noexcept; + void swap(weak_bptr& other) noexcept; + + uint32_t use_count() const noexcept; + bool expired() const noexcept; + bptr<T> lock() const noexcept; + + bool operator==(const weak_bptr<const T>& other) const noexcept; +}; + +} // namespace floormat |