11 namespace intrusive_ptr {
29 friend void Ref(
const T*);
31 friend void Unref(
const T*);
32 mutable uint64_t _references = 1;
36 inline void Ref(
const T* m) {
42 inline void Unref(
const T* m) {
43 if ( m && --m->_references == 0 )
73 using const_pointer =
const T*;
75 using element_type = T;
79 using const_reference =
const T&;
119 IntrusivePtr(IntrusivePtr<U> other) noexcept
120 requires(std::is_convertible_v<U*, T*>)
130 void swap(IntrusivePtr& other) noexcept { std::swap(ptr_, other.ptr_); }
132 friend void swap(IntrusivePtr& a, IntrusivePtr& b) noexcept {
134 swap(a.ptr_, b.ptr_);
142 pointer
release() noexcept {
return std::exchange(ptr_,
nullptr); }
149 pointer get() const noexcept {
return ptr_; }
151 pointer operator->() const noexcept {
return ptr_; }
153 reference operator*() const noexcept {
return *ptr_; }
155 bool operator!() const noexcept {
return ! ptr_; }
157 explicit operator bool() const noexcept {
return ptr_ !=
nullptr; }
160 pointer ptr_ =
nullptr;
171 template<
class T,
class... Ts>
183 template<
class T,
class U>
202 bool operator==(std::nullptr_t,
const IntrusivePtr<T>& x) {
210 bool operator!=(
const IntrusivePtr<T>& x, std::nullptr_t) {
211 return static_cast<bool>(x);
218 bool operator!=(std::nullptr_t,
const IntrusivePtr<T>& x) {
219 return static_cast<bool>(x);
228 bool operator==(
const IntrusivePtr<T>& x,
const T* y) {
236 bool operator==(
const T* x,
const IntrusivePtr<T>& y) {
244 bool operator!=(
const IntrusivePtr<T>& x,
const T* y) {
252 bool operator!=(
const T* x,
const IntrusivePtr<T>& y) {
264 template<
class T,
class U>
265 auto operator==(
const IntrusivePtr<T>& x,
const IntrusivePtr<U>& y) -> decltype(x.get() == y.get()) {
266 return x.get() == y.get();
272 template<
class T,
class U>
273 auto operator!=(
const IntrusivePtr<T>& x,
const IntrusivePtr<U>& y) -> decltype(x.get() != y.get()) {
274 return x.get() != y.get();
Definition: intrusive-ptr.h:67
IntrusivePtr(intrusive_ptr::NewRef, pointer raw_ptr) noexcept
Definition: intrusive-ptr.h:107
constexpr IntrusivePtr(intrusive_ptr::AdoptRef, pointer raw_ptr) noexcept
Definition: intrusive-ptr.h:97
pointer release() noexcept
Definition: intrusive-ptr.h:142
IntrusivePtr< T > make_intrusive(Ts &&... args)
Definition: intrusive-ptr.h:172
Definition: intrusive-ptr.h:26
IntrusivePtr< T > cast_intrusive(IntrusivePtr< U > p) noexcept
Definition: intrusive-ptr.h:184
Definition: intrusive-ptr.h:17
Definition: intrusive-ptr.h:23