12 [[nodiscard]]
WeakPtr() noexcept : counter(
nullptr) {}
13 [[nodiscard]]
WeakPtr(std::nullptr_t) noexcept : counter(
nullptr) {}
17 requires(std::convertible_to<Y*, T*>)
21 counter->addWeakCount();
27 requires(std::convertible_to<Y*, T*>)
31 counter->addWeakCount();
37 requires(std::convertible_to<Y*, T*>)
40 other.counter =
nullptr;
45 counter->releaseWeak();
51 requires(std::convertible_to<Y*, T*>)
56 counter->addWeakCount();
64 requires(std::convertible_to<Y*, T*>)
69 counter->addWeakCount();
77 requires(std::convertible_to<Y*, T*>)
81 other.counter =
nullptr;
86 [[nodiscard]]
int use_count()
const {
return counter ? counter->getShareCount() : 0; }
88 [[nodiscard]]
bool expired()
const {
return use_count() == 0; }
92 [[nodiscard]] T* get()
const {
return counter ? counter->get() :
nullptr; }
94 [[nodiscard]] T* operator->()
const {
return get(); }
96 [[nodiscard]] T& operator*()
const {
return *get(); }
98 [[nodiscard]]
explicit operator bool()
const {
return get() !=
nullptr; }