44 if (m_ptr !=
nullptr) {
49 constexpr ~IntrusiveSharedPtr() {
50 if (m_ptr !=
nullptr) {
60 if (m_ptr !=
nullptr) {
69 requires(!std::same_as<T, U> && std::convertible_to<U*, T*>)
73 if (m_ptr !=
nullptr) {
85 if (m_ptr ==
rhs.m_ptr) {
89 if (m_ptr !=
nullptr) {
95 if (m_ptr !=
nullptr) {
106 template <
typename U>
107 requires(!std::same_as<T, U> && std::convertible_to<U*, T*>)
111 if (m_ptr ==
rhs.m_ptr) {
115 if (m_ptr !=
nullptr) {
116 dec_ref_count(m_ptr);
121 if (m_ptr !=
nullptr) {
122 inc_ref_count(m_ptr);
132 : m_ptr{std::exchange(
rhs.m_ptr,
nullptr)} {}
137 template <
typename U>
138 requires(!std::same_as<T, U> && std::convertible_to<U*, T*>)
141 : m_ptr{std::exchange(
rhs.m_ptr,
nullptr)} {}
149 if (m_ptr ==
rhs.m_ptr) {
153 std::swap(m_ptr,
rhs.m_ptr);
162 template <
typename U>
163 requires(!std::same_as<T, U> && std::convertible_to<U*, T*>)
166 if (m_ptr ==
rhs.m_ptr) {
170 std::swap(m_ptr,
rhs.m_ptr);
202 return lhs.m_ptr ==
rhs.m_ptr;
212 return lhs.m_ptr !=
rhs.m_ptr;
219 std::nullptr_t)
noexcept {
220 return lhs.m_ptr ==
nullptr;
228 return nullptr ==
rhs.m_ptr;
236 std::nullptr_t)
noexcept {
237 return lhs.m_ptr !=
nullptr;
246 return nullptr !=
rhs.m_ptr;
259template <
typename T,
typename... Args>
260IntrusiveSharedPtr<T> make_intrusive_shared(Args&&... args) {
261 return IntrusiveSharedPtr<T>{
new T(std::forward<Args>(args)...)};
273template <
typename T,
typename Alloc,
typename... Args>
274IntrusiveSharedPtr<T> allocate_intrusive_shared(Alloc alloc, Args&&... args) {
275 auto ptr = std::allocator_traits<Alloc>::allocate(alloc,
sizeof(T));
276 std::allocator_traits<Alloc>::construct(alloc, ptr,
277 std::forward<Args>(args)...);
278 return IntrusiveSharedPtr<T>{ptr};
Definition intrusive_shared_ptr.hpp:27
constexpr IntrusiveSharedPtr(IntrusiveSharedPtr< U > &&rhs) noexcept
Definition intrusive_shared_ptr.hpp:140
constexpr IntrusiveSharedPtr< T > & operator=(IntrusiveSharedPtr< T > &&rhs) noexcept
Definition intrusive_shared_ptr.hpp:147
friend constexpr bool operator==(std::nullptr_t, const IntrusiveSharedPtr< T > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:226
constexpr T * get() const noexcept
Definition intrusive_shared_ptr.hpp:178
constexpr IntrusiveSharedPtr(const IntrusiveSharedPtr< T > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:58
constexpr T * operator->() const noexcept
Definition intrusive_shared_ptr.hpp:188
friend constexpr bool operator!=(const IntrusiveSharedPtr< T > &lhs, std::nullptr_t) noexcept
Definition intrusive_shared_ptr.hpp:235
friend constexpr bool operator==(const IntrusiveSharedPtr< T > &lhs, std::nullptr_t) noexcept
Definition intrusive_shared_ptr.hpp:218
friend constexpr bool operator==(const IntrusiveSharedPtr< T > &lhs, const IntrusiveSharedPtr< T > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:200
constexpr IntrusiveSharedPtr() noexcept=default
Constructs an empty intrusive shared pointer.
constexpr IntrusiveSharedPtr(T *ptr) noexcept
Definition intrusive_shared_ptr.hpp:43
friend constexpr bool operator!=(std::nullptr_t, const IntrusiveSharedPtr< T > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:244
constexpr IntrusiveSharedPtr(IntrusiveSharedPtr< T > &&rhs) noexcept
Definition intrusive_shared_ptr.hpp:131
constexpr T & operator*() const noexcept
Definition intrusive_shared_ptr.hpp:183
constexpr IntrusiveSharedPtr(const IntrusiveSharedPtr< U > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:71
friend constexpr bool operator!=(const IntrusiveSharedPtr< T > &lhs, const IntrusiveSharedPtr< T > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:210
constexpr IntrusiveSharedPtr< T > & operator=(const IntrusiveSharedPtr< T > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:83