24 using element_type = T;
32 if (_ptr) _ptr->ref();
47 if (_ptr) _ptr->ref();
50 explicit ref_ptr(T* ptr) noexcept :
53 if (_ptr) _ptr->ref();
57 explicit ref_ptr(R* ptr) noexcept :
60 if (_ptr) _ptr->ref();
64 ref_ptr(
decltype(
nullptr)) noexcept :
69 if (_ptr) _ptr->unref();
74 if (_ptr) _ptr->unref();
78 ref_ptr& operator=(T* ptr)
80 if (ptr == _ptr)
return *
this;
86 if (_ptr) _ptr->ref();
89 if (temp_ptr) temp_ptr->unref();
94 ref_ptr& operator=(
const ref_ptr& rhs)
96 if (rhs._ptr == _ptr)
return *
this;
102 if (_ptr) _ptr->ref();
105 if (temp_ptr) temp_ptr->unref();
111 ref_ptr& operator=(
const ref_ptr<R>& rhs)
113 if (rhs._ptr == _ptr)
return *
this;
119 if (_ptr) _ptr->ref();
122 if (temp_ptr) temp_ptr->unref();
131 if (rhs._ptr == _ptr)
return *
this;
133 if (_ptr) _ptr->unref();
143 bool operator<(
const ref_ptr<R>& rhs)
const {
return (_ptr < rhs._ptr); }
146 bool operator==(
const ref_ptr<R>& rhs)
const {
return (rhs._ptr == _ptr); }
149 bool operator!=(
const ref_ptr<R>& rhs)
const {
return (rhs._ptr != _ptr); }
152 bool operator<(
const R* rhs)
const {
return (_ptr < rhs); }
155 bool operator==(
const R* rhs)
const {
return (rhs == _ptr); }
158 bool operator!=(
const R* rhs)
const {
return (rhs != _ptr); }
160 bool valid() const noexcept {
return _ptr !=
nullptr; }
162 explicit operator bool() const noexcept {
return valid(); }
165 operator T*()
const noexcept {
return _ptr; }
167 void operator[](
int)
const =
delete;
169 T& operator*() const noexcept {
return *_ptr; }
171 T* operator->() const noexcept {
return _ptr; }
173 T* get() const noexcept {
return _ptr; }
175 T* release_nodelete() noexcept
179 if (_ptr) _ptr->unref_nodelete();
185 void swap(ref_ptr& rhs)
noexcept
193 ref_ptr<R> cast()
const {
return ref_ptr<R>(_ptr ? _ptr->template cast<R>() :
nullptr); }
197 friend class ref_ptr;