Add rcp::use_count()
This commit is contained in:
1 parent
af0e0d0084
commit
d9a9a88a24
2 files changed
+24
No files matched your search
@@ -119,6 +119,11 @@ public:
|
||||
other.ptr = nullptr;
|
||||
}
|
||||
|
||||
int use_count() const
|
||||
{
|
||||
return ptr ? ptr->rcp_count() : 0;
|
||||
}
|
||||
|
||||
void swap(rcp & other) noexcept
|
||||
{
|
||||
T * tmp = ptr;
|
||||
@@ -232,6 +237,10 @@ rcp<T> rcp_dynamic_cast(rcp<U> && other)
|
||||
delete this; \
|
||||
} \
|
||||
} \
|
||||
int rcp_count() const \
|
||||
{ \
|
||||
return ref_count.load(std::memory_order_relaxed); \
|
||||
} \
|
||||
private: \
|
||||
mutable std::atomic<int> ref_count{0}; \
|
||||
rcp_managed(classname)
|
||||
|
||||
Reference in new issue
Block a user