12 [[nodiscard]] WeakPtr() noexcept : counter(
nullptr) {}
13 [[nodiscard]] WeakPtr(std::nullptr_t) noexcept : counter(
nullptr) {}
15 [[nodiscard]] WeakPtr(WeakPtr
const& other) {
16 counter = other.counter;
18 counter->addWeakCount();
22 [[nodiscard]] WeakPtr(WeakPtr&& other)
noexcept {
23 counter = other.counter;
24 other.counter =
nullptr;
27 WeakPtr& operator=(WeakPtr
const& other) {
30 counter->releaseWeak();
32 counter = other.counter;
34 counter->addWeakCount();
40 WeakPtr& operator=(WeakPtr&& other)
noexcept {
43 counter->releaseWeak();
45 counter = other.counter;
46 other.counter =
nullptr;
52 [[nodiscard]]
explicit WeakPtr(
SharedPtr<Y> const& other)
53 requires(std::convertible_to<Y*, T*>)
57 counter->addWeakCount();
62 [[nodiscard]]
explicit WeakPtr(WeakPtr<Y>
const& other)
63 requires(std::convertible_to<Y*, T*>)
67 counter->addWeakCount();
72 [[nodiscard]]
explicit WeakPtr(WeakPtr<Y>&& other)
73 requires(std::convertible_to<Y*, T*>)
76 other.counter =
nullptr;
81 counter->releaseWeak();
87 requires(std::convertible_to<Y*, T*>)
92 counter->addWeakCount();
99 WeakPtr<T>& operator=(WeakPtr<Y>
const& other)
100 requires(std::convertible_to<Y*, T*>)
105 counter->addWeakCount();
112 WeakPtr<T>& operator=(WeakPtr<Y>&& other)
113 requires(std::convertible_to<Y*, T*>)
117 other.counter =
nullptr;
122 [[nodiscard]]
int use_count()
const {
return counter ? counter->getShareCount() : 0; }
124 [[nodiscard]]
bool expired()
const {
return use_count() == 0; }
128 [[nodiscard]] T* get()
const {
return counter ? counter->get() :
nullptr; }
130 [[nodiscard]] T* operator->()
const {
return get(); }
132 [[nodiscard]] T& operator*()
const {
return *get(); }
134 [[nodiscard]]
explicit operator bool()
const {
return get() !=
nullptr; }