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();
65 if (_ptr) _ptr->unref();
70 if (_ptr) _ptr->unref();
74 ref_ptr& operator=(T* ptr)
76 if (ptr == _ptr)
return *
this;
82 if (_ptr) _ptr->ref();
85 if (temp_ptr) temp_ptr->unref();
90 ref_ptr& operator=(
const ref_ptr& rhs)
92 if (rhs._ptr == _ptr)
return *
this;
98 if (_ptr) _ptr->ref();
101 if (temp_ptr) temp_ptr->unref();
107 ref_ptr& operator=(
const ref_ptr<R>& rhs)
109 if (rhs._ptr == _ptr)
return *
this;
115 if (_ptr) _ptr->ref();
118 if (temp_ptr) temp_ptr->unref();
127 if (rhs._ptr == _ptr)
return *
this;
129 if (_ptr) _ptr->unref();
139 bool operator<(
const ref_ptr<R>& rhs)
const {
return (_ptr < rhs._ptr); }
142 bool operator==(
const ref_ptr<R>& rhs)
const {
return (rhs._ptr == _ptr); }
145 bool operator!=(
const ref_ptr<R>& rhs)
const {
return (rhs._ptr != _ptr); }
148 bool operator<(
const R* rhs)
const {
return (_ptr < rhs); }
151 bool operator==(
const R* rhs)
const {
return (rhs == _ptr); }
154 bool operator!=(
const R* rhs)
const {
return (rhs != _ptr); }
156 bool valid() const noexcept {
return _ptr !=
nullptr; }
158 explicit operator bool() const noexcept {
return valid(); }
161 operator T*()
const noexcept {
return _ptr; }
163 void operator[](
int)
const =
delete;
165 T& operator*() const noexcept {
return *_ptr; }
167 T* operator->() const noexcept {
return _ptr; }
169 T* get() const noexcept {
return _ptr; }
171 T* release_nodelete() noexcept
175 if (_ptr) _ptr->unref_nodelete();
181 void swap(ref_ptr& rhs) noexcept
189 ref_ptr<R> cast()
const {
return ref_ptr<R>(_ptr ? _ptr->template cast<R>() :
nullptr); }
193 friend class ref_ptr;
ref_ptr & operator=(ref_ptr< R > &&rhs)
move assignment
Definition: ref_ptr.h:125
ref_ptr(ref_ptr< R > &&rhs) noexcept
move constructor
Definition: ref_ptr.h:37