12 template <
typename... Args>
13 [[nodiscard]]
static SharedPtr<T> make(Args&&... args) {
14 return SharedPtr<T>(
new T(std::forward<Args>(args)...));
17 [[nodiscard]] SharedPtr() noexcept : counter(
nullptr) {}
18 [[nodiscard]] SharedPtr(std::nullptr_t) noexcept : counter(
nullptr) {}
23 [[nodiscard]]
explicit SharedPtr(SharedPtr<Y>
const& other)
24 requires(std::convertible_to<Y*, T*>)
28 counter->addShareCount();
33 [[nodiscard]]
explicit SharedPtr(SharedPtr<Y>&& other)
34 requires(std::convertible_to<Y*, T*>)
37 other.counter =
nullptr;
41 [[nodiscard]]
explicit SharedPtr(
WeakPtr<Y> const& other)
42 requires(std::convertible_to<Y*, T*>)
46 counter->addShareCount();
57 SharedPtr<T>& operator=(SharedPtr<Y>
const& other)
58 requires(std::convertible_to<Y*, T*>)
63 counter->addShareCount();
70 SharedPtr<T>& operator=(SharedPtr<Y>&& other)
71 requires(std::convertible_to<Y*, T*>)
75 other.counter =
nullptr;
81 SharedPtr<T>& operator=(
WeakPtr<Y> const& other)
82 requires(std::convertible_to<Y*, T*>)
86 counter->addShareCount();
91 [[nodiscard]] T* get()
const {
return counter ? counter->get() :
nullptr; }
93 [[nodiscard]] T* operator->()
const {
return get(); }
95 [[nodiscard]] T& operator*()
const {
return *get(); }
97 [[nodiscard]]
explicit operator bool()
const {
return get() !=
nullptr; }
99 [[nodiscard]]
int use_count()
const {
return counter ? counter->getShareCount() : 0; }