Rename ctl -> rc

ctl is overloaded...
This commit is contained in:
Steven Dee (Jōshin) 2024-06-19 22:53:22 -07:00
parent 2edff8f23a
commit 0b710a112d
No known key found for this signature in database

View file

@ -90,46 +90,46 @@ class shared_ptr
using element_type = T; // TODO(mrdomino): remove extent? using element_type = T; // TODO(mrdomino): remove extent?
constexpr shared_ptr(nullptr_t = nullptr) noexcept constexpr shared_ptr(nullptr_t = nullptr) noexcept
: p(nullptr), ctl(nullptr) : p(nullptr), rc(nullptr)
{ {
} }
explicit shared_ptr(auto* const p) : p(p), ctl(__::shared_pointer<T>::make(p)) explicit shared_ptr(auto* const p) : p(p), rc(__::shared_pointer<T>::make(p))
{ {
} }
shared_ptr(const shared_ptr& r) noexcept : p(r.p), ctl(r.ctl) shared_ptr(const shared_ptr& r) noexcept : p(r.p), rc(r.rc)
{ {
if (ctl) if (rc)
ctl->keep_shared(); rc->keep_shared();
} }
shared_ptr(shared_ptr&& r) noexcept : p(r.p), ctl(r.ctl) shared_ptr(shared_ptr&& r) noexcept : p(r.p), rc(r.rc)
{ {
r.p = nullptr; r.p = nullptr;
r.ctl = nullptr; r.rc = nullptr;
} }
template <typename U> template <typename U>
shared_ptr(const shared_ptr<U>& r, T* const p) noexcept : p(p), ctl(r.ctl) shared_ptr(const shared_ptr<U>& r, T* const p) noexcept : p(p), rc(r.rc)
{ {
if (ctl) if (rc)
ctl->keep_shared(); rc->keep_shared();
} }
template <typename U> template <typename U>
shared_ptr(shared_ptr<U>&& r, T* const p) noexcept : p(p), ctl(r.ctl) shared_ptr(shared_ptr<U>&& r, T* const p) noexcept : p(p), rc(r.rc)
{ {
r.p = nullptr; r.p = nullptr;
r.ctl = nullptr; r.rc = nullptr;
} }
// TODO(mrdomino): moar ctors // TODO(mrdomino): moar ctors
~shared_ptr() ~shared_ptr()
{ {
if (ctl) if (rc)
ctl->drop_shared(); rc->drop_shared();
} }
shared_ptr& operator=(shared_ptr r) noexcept shared_ptr& operator=(shared_ptr r) noexcept
@ -140,10 +140,10 @@ class shared_ptr
void reset() noexcept void reset() noexcept
{ {
if (ctl) if (rc)
ctl->drop_shared(); rc->drop_shared();
p = nullptr; p = nullptr;
ctl = nullptr; rc = nullptr;
} }
void reset(auto* const p2) void reset(auto* const p2)
@ -155,7 +155,7 @@ class shared_ptr
{ {
using ctl::swap; using ctl::swap;
swap(p, r.p); swap(p, r.p);
swap(ctl, r.ctl); swap(rc, r.rc);
} }
element_type* get() const noexcept element_type* get() const noexcept
@ -186,7 +186,7 @@ class shared_ptr
size_t use_count() const noexcept size_t use_count() const noexcept
{ {
return ctl ? ctl->use_count() : 0; return rc ? rc->use_count() : 0;
} }
explicit operator bool() const noexcept explicit operator bool() const noexcept
@ -204,7 +204,7 @@ class shared_ptr
private: private:
T* p; T* p;
__::shared_control* ctl; __::shared_control* rc;
}; };
// TODO(mrdomino): non-member functions (make_shared et al) // TODO(mrdomino): non-member functions (make_shared et al)