1 #ifndef CYCLE_PTR_DETAIL_INTRUSIVE_PTR_H 2 #define CYCLE_PTR_DETAIL_INTRUSIVE_PTR_H 10 namespace cycle_ptr::detail {
23 using element_type = T;
27 constexpr
intrusive_ptr([[maybe_unused]] std::nullptr_t nil) noexcept
34 if (ptr_ !=
nullptr && acquire)
35 intrusive_ptr_add_ref(ptr_);
43 : ptr_(std::exchange(x.ptr_,
nullptr))
49 T* old = std::exchange(ptr_, x.ptr_);
51 intrusive_ptr_add_ref(ptr_);
53 intrusive_ptr_release(old);
60 T* old = std::exchange(ptr_, std::exchange(x.ptr_,
nullptr));
62 intrusive_ptr_release(old);
68 intrusive_ptr_release(ptr_);
74 intrusive_ptr_release(std::exchange(ptr_,
nullptr));
80 std::swap(ptr_, other.ptr_);
86 return std::exchange(ptr_,
nullptr);
95 auto operator*()
const 98 assert(ptr_ !=
nullptr);
102 auto operator->()
const 105 assert(ptr_ !=
nullptr);
109 explicit operator bool()
const noexcept {
110 return ptr_ !=
nullptr;
129 template<
typename T,
typename U>
133 return x.get() == y.get();
138 template<
typename T,
typename U>
147 template<
typename T,
typename U>
174 template<
typename T,
typename U>
183 template<
typename T,
typename U>
192 template<
typename T,
typename U>
219 template<
typename T,
typename U>
223 return x.get() < y.get();
228 template<
typename T,
typename U>
237 template<
typename T,
typename U>
250 return std::less<typename intrusive_ptr<U>::element_type*>()(
nullptr, y.get());
259 return std::less<typename intrusive_ptr<T>::element_type*>()(x.get(),
nullptr);
264 template<
typename T,
typename U>
273 template<
typename T,
typename U>
282 template<
typename T,
typename U>
309 template<
typename T,
typename U>
318 template<
typename T,
typename U>
327 template<
typename T,
typename U>
340 return !(y <
nullptr);
349 return !(
nullptr < x);
354 template<
typename T,
typename U>
363 template<
typename T,
typename U>
372 template<
typename T,
typename U>
385 return !(
nullptr < y);
394 return !(x <
nullptr);
399 template<
typename Char,
typename Traits,
typename T>
401 -> std::basic_ostream<Char, Traits>& {
402 return out << ptr.get();
auto swap(intrusive_ptr< T > &x, intrusive_ptr< T > &y) noexcept -> void
Swap operation.
Definition: intrusive_ptr.h:121
auto operator<<(std::basic_ostream< Char, Traits > &out, const intrusive_ptr< T > &ptr) -> std::basic_ostream< Char, Traits > &
Write pointer to output stream.
Definition: intrusive_ptr.h:400
auto operator>([[maybe_unused]] std::nullptr_t x, const intrusive_ptr< U > &y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:292
auto operator>(T *x, const intrusive_ptr< U > &y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:274
auto operator!=(const intrusive_ptr< T > &x, const intrusive_ptr< U > &y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:175
auto operator>=(T *x, const intrusive_ptr< U > &y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:364
auto operator<=(const intrusive_ptr< T > &x, const intrusive_ptr< U > &y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:310
auto operator>=(const intrusive_ptr< T > &x, const intrusive_ptr< U > &y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:355
auto operator<(const intrusive_ptr< T > &x, const intrusive_ptr< U > &y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:220
auto operator<=(T *x, const intrusive_ptr< U > &y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:319
auto operator>(const intrusive_ptr< T > &x, [[maybe_unused]] std::nullptr_t y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:301
auto operator>=(const intrusive_ptr< T > &x, U *y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:373
auto operator<(const intrusive_ptr< T > &x, U *y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:238
auto operator<([[maybe_unused]] std::nullptr_t x, const intrusive_ptr< U > &y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:247
Intrusive pointer.
Definition: intrusive_ptr.h:21
auto operator==(const intrusive_ptr< T > &x, const intrusive_ptr< U > &y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:130
auto operator!=(T *x, const intrusive_ptr< U > &y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:184
auto operator>(const intrusive_ptr< T > &x, const intrusive_ptr< U > &y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:265
auto operator<=([[maybe_unused]] std::nullptr_t x, const intrusive_ptr< U > &y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:337
auto operator>=(const intrusive_ptr< T > &x, [[maybe_unused]] std::nullptr_t y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:391
auto operator==([[maybe_unused]] std::nullptr_t x, const intrusive_ptr< U > &y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:157
auto operator<=(const intrusive_ptr< T > &x, U *y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:328
auto operator==(T *x, const intrusive_ptr< U > &y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:139
auto operator>(const intrusive_ptr< T > &x, U *y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:283
auto operator==(const intrusive_ptr< T > &x, [[maybe_unused]] std::nullptr_t y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:166
auto operator<(T *x, const intrusive_ptr< U > &y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:229
auto operator!=([[maybe_unused]] std::nullptr_t x, const intrusive_ptr< U > &y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:202
auto operator==(const intrusive_ptr< T > &x, U *y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:148
auto operator!=(const intrusive_ptr< T > &x, [[maybe_unused]] std::nullptr_t y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:211
auto operator>=([[maybe_unused]] std::nullptr_t x, const intrusive_ptr< U > &y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:382
auto operator<=(const intrusive_ptr< T > &x, [[maybe_unused]] std::nullptr_t y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:346
auto operator!=(const intrusive_ptr< T > &x, U *y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:193
auto operator<(const intrusive_ptr< T > &x, [[maybe_unused]] std::nullptr_t y) noexcept -> bool
Comparison.
Definition: intrusive_ptr.h:256